org.bukkit.event.player.PlayerToggleSneakEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerToggleSneakEvent. 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: GadgetsListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onToggleSneak(PlayerToggleSneakEvent e) {
    if (e.isSneaking()) {
        Player p = e.getPlayer();

        if (p.getInventory().getChestplate() != null) {
            SlimefunItem chestplate = SlimefunItem.getByItem(p.getInventory().getChestplate());
            handleChestplate(p, chestplate);
        }

        if (p.getInventory().getBoots() != null) {
            SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
            handleBoots(p, boots);
        }

        if (SlimefunUtils.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true)) {
            InfusedMagnet magnet = (InfusedMagnet) SlimefunItems.INFUSED_MAGNET.getItem();

            if (Slimefun.hasUnlocked(p, magnet, true)) {
                new MagnetTask(p, magnet.getRadius()).scheduleRepeating(0, 8);
            }
        }
    }
}
 
Example #2
Source File: NameTagX.java    From TAB with Apache License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void a(PlayerToggleSneakEvent e) {
	ITabPlayer p = Shared.getPlayer(e.getPlayer().getUniqueId());
	if (p == null) return;
	if (!p.disabledNametag) Shared.featureCpu.runMeasuredTask("processing PlayerToggleSneakEvent", CPUFeature.NAMETAGX_EVENT_SNEAK, new Runnable() {
		public void run() {
			p.getArmorStands().forEach(a -> a.sneak(e.isSneaking()));
		}
	});
}
 
Example #3
Source File: ShadowDive.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onSneak(PlayerToggleSneakEvent event) {
	Player player = event.getPlayer();
	if (!player.hasPermission("minetinker.modifiers.shadowdive.use")) return;

	ItemStack boots = player.getInventory().getBoots();
	if (!modManager.isArmorViable(boots)) return;
	if (!modManager.hasMod(boots, this)) return;

	if (event.isSneaking() && !player.isGliding()) { //enable
		Location loc = player.getLocation();
		byte lightlevel = player.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()).getLightLevel();
		boolean combatTagged = PlayerInfo.isCombatTagged(player);
		ChatWriter.logModifier(player, event, this, boots,
				String.format("LightLevel(%d/%d)", lightlevel, this.requiredLightLevel),
				String.format("InCombat(%b)", combatTagged));
		if (lightlevel > this.requiredLightLevel || player.hasPotionEffect(PotionEffectType.GLOWING)) {
			ChatWriter.sendActionBar(player, ChatColor.RED + this.getName() + ": "
					+ LanguageManager.getString("Modifier.Shadow-Dive.LightToHigh", player));
			return;
		}

		if (combatTagged) {
			ChatWriter.sendActionBar(player, ChatColor.RED + this.getName() + ": "
					+ LanguageManager.getString("Modifier.Shadow-Dive.InCombat", player));
			return;
		}

		hidePlayer(player);

	} else { //disable
		if (!activePlayers.contains(player)) return;
		showPlayer(player);
	}
}
 
Example #4
Source File: PlayerSneakListener.java    From ViaVersion with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void playerToggleSneak(PlayerToggleSneakEvent event) {
    Player player = event.getPlayer();
    UserConnection userConnection = getUserConnection(player);
    if (userConnection == null) return;
    ProtocolInfo info = userConnection.getProtocolInfo();
    if (info == null) return;

    int protocolVersion = info.getProtocolVersion();
    if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
        setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
        if (event.isSneaking())
            sneakingUuids.add(player.getUniqueId());
        else
            sneakingUuids.remove(player.getUniqueId());

        if (!useCache) return;
        if (event.isSneaking())
            sneaking.put(player, true);
        else
            sneaking.remove(player);
    } else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getId()) {
        setHeight(player, event.isSneaking() ? HEIGHT_1_9 : STANDING_HEIGHT);
        if (!useCache) return;
        if (event.isSneaking())
            sneaking.put(player, false);
        else
            sneaking.remove(player);
    }
}
 
Example #5
Source File: DataUpdaterEvents.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onToggleSneak(final PlayerToggleSneakEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    if (user != null) {
        user.getDataMap().setValue(DataKey.SNEAKING, event.isSneaking());
        if (!event.isSneaking()) {
            user.getDataMap().setValue(DataKey.LAST_SNEAK_DURATION, user.getTimestampMap().passedTime(TimestampKey.LAST_SNEAK_TOGGLE));
        }
        user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_SNEAK_TOGGLE);
    }
}
 
Example #6
Source File: Transporter.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true)
public void Teleport(PlayerToggleSneakEvent event)
{
	if(event.isSneaking())
	{
		Player player = event.getPlayer();
		Block b = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
		if(b.getType() == Material.QUARTZ_ORE)
		{
			UUID owner = getBlocksOwner(b);
			if(owner != null)
			{
				AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
				if(p != null)
				{
					Teleporter tele = teleporters.get(owner);
					if(tele.isLinked() && tele.getOwner().getTeam() == p.getTeam() && tele.canUse())
					{
						Location loc;
						//if(new Loc(b.getLocation()).isEqual(tele.getLoc1()))
						if(tele.getLoc1().equals(b.getLocation()))
							loc = tele.getLoc2().toLocation();
						else
							loc = tele.getLoc1().toLocation();
						loc.setY(loc.getY()+1);
						player.teleport(this.getMiddle(loc));
						loc.getWorld().playEffect(loc, Effect.MOBSPAWNER_FLAMES, 1);
						tele.getLoc1().toLocation().getWorld().playSound(tele.getLoc1().toLocation(), Sound.ENDERMAN_TELEPORT, 1F,(float)Math.random());
						tele.getLoc2().toLocation().getWorld().playSound(tele.getLoc2().toLocation(), Sound.ENDERMAN_TELEPORT, 1F,(float)Math.random());
						tele.delay();
						event.setCancelled(true);
					}
				}
			}
		}
	}
}
 
Example #7
Source File: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onShift(PlayerToggleSneakEvent event) {
	Player player = event.getPlayer();
	Connection connection = ProtocolSupportAPI.getConnection(player);
	if (
		player.isInsideVehicle() &&
		(connection != null) &&
		(connection.getVersion().getProtocolType() == ProtocolType.PC) &&
		connection.getVersion().isBeforeOrEq(ProtocolVersion.MINECRAFT_1_5_2)
	) {
		player.leaveVehicle();
	}
}
 
Example #8
Source File: TauntListener.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void pressedTauntKey(PlayerToggleSneakEvent e) {
	Player player = e.getPlayer();
       GameMap gameMap = MatchManager.get().getPlayerMap(player);
       if (gameMap == null) {
       	return;
       }
	String uuid = e.getPlayer().getUniqueId().toString();
	if (!player.isSneaking()) {
		if (lastHandSwap.containsKey(uuid)) {
			if (System.currentTimeMillis() - lastHandSwap.get(uuid) < 500) {
				if (lastTaunt.containsKey(uuid)) {
					if (System.currentTimeMillis() - lastTaunt.get(uuid) < SkyWarsReloaded.getCfg().getCooldown()*1000) {
						int cooldown = (int) ((SkyWarsReloaded.getCfg().getCooldown()*1000 - (System.currentTimeMillis() - lastTaunt.get(uuid)))/1000);
						int seconds = (cooldown % 60) + 1;
						int minutes = (cooldown-(seconds - 1)) / 60;
						String cooldownText = "";
						if (minutes > 0) {
							cooldownText = cooldownText + minutes + " Minutes ";
						} 
						if (seconds > 0) {
							cooldownText = cooldownText + seconds + " Seconds";
						}
						
						e.getPlayer().sendMessage(new Messaging.MessageFormatter().setVariable("timeleft", cooldownText).format("error.cooldown"));
						return;
					} else {
						lastTaunt.remove(uuid);
					}
				}
				PlayerStat ps = PlayerStat.getPlayerStats(e.getPlayer());
				if (ps != null) {
                       String tauntName = ps.getTaunt();
                       TauntOption taunt = (TauntOption) TauntOption.getPlayerOptionByKey(tauntName);
                       if (taunt != null) {
                           if (!taunt.getKey().equals("none")) {
                               taunt.performTaunt(e.getPlayer());
                           }
                       }
                       lastHandSwap.remove(uuid);
                       lastTaunt.put(uuid, System.currentTimeMillis());
                   }
			} else {
				lastHandSwap.put(uuid, System.currentTimeMillis());
			}
		} else {
			lastHandSwap.put(uuid, System.currentTimeMillis());
		}
	}	
}