Java Code Examples for org.bukkit.entity.Player#setAllowFlight()

The following examples show how to use org.bukkit.entity.Player#setAllowFlight() . 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: DoubleJumpKit.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void update() {
    int diff = (int) (System.currentTimeMillis() - lastUpdate);
    lastUpdate = System.currentTimeMillis();
    float toAddExp = rechargeTime > 0 ? (float) (diff / (rechargeTime * 1000)) : 1.0f;
    for(UUID uuid : players) {
        Player player = Bukkit.getPlayer(uuid);
        if(player.getExp() < 1.0f && (rechargeBeforeLanding || landed.contains(uuid))) {
            player.setExp(player.getExp() + toAddExp > 1.0f ? 1.0f : player.getExp() + toAddExp);
        } else if(player.getExp() > 1.0f) {
            player.setExp(1.0f);
        }
        if(player.getExp() >= 1.0f) {
            player.setAllowFlight(true);
        }
    }
}
 
Example 2
Source File: Game.java    From Survival-Games with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void addSpectator(Player p) {
	if (mode != GameMode.INGAME) {
		msgmgr.sendMessage(PrefixType.WARNING, "You can only spectate running games!", p);
		return;
	}

	saveInv(p);
	clearInv(p);
	p.teleport(SettingsManager.getInstance().getSpawnPoint(gameID, 1).add(0, 10, 0));

	HookManager.getInstance().runHook("PLAYER_SPECTATE", "player-"+p.getName());

	for (Player pl: Bukkit.getOnlinePlayers()) {
		pl.hidePlayer(p);
	}

	p.setAllowFlight(true);
	p.setFlying(true);
	spectators.add(p.getName());
	msgmgr.sendMessage(PrefixType.INFO, "You are now spectating! Use /sg spectate again to return to the lobby.", p);
	msgmgr.sendMessage(PrefixType.INFO, "Right click while holding shift to teleport to the next ingame player, left click to go back.", p);
	nextspec.put(p, 0);
}
 
Example 3
Source File: Acrobat.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void AcrobatDoubleJump(PlayerToggleFlightEvent event) 
{  
	Player player = event.getPlayer();
	if(player.getGameMode() != GameMode.CREATIVE) 
	{
		AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
		if(Game.isGameRunning() && p != null && p.getKit().equals(this))
		{
			Delays.getInstance().addDelay(player, System.currentTimeMillis()+10000, this.getInternalName());
		    event.setCancelled(true);
		    player.setAllowFlight(false);
		    player.setFlying(false);		    
		    player.setVelocity(player.getLocation().getDirection().setY(1).multiply(1));
		    player.playSound(player.getLocation(), Sound.ZOMBIE_INFECT, 1.0F, 2.0F);
		}
		else
		{
			player.setAllowFlight(false);
			player.setFlying(false);
		}
	}
}
 
Example 4
Source File: DoubleJumpFeature.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
@GameEvent
public void e(@Nonnull PlayerToggleFlightEvent event) {
    final Player player = event.getPlayer();
    if (player.getGameMode() != GameMode.CREATIVE) {
        if (!disabled.contains(player.getUniqueId())) {
            event.setCancelled(true);
            player.setAllowFlight(false);
            player.setFlying(false);
            player.setVelocity(player.getLocation().getDirection().multiply(1.6).setY(1));
            player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_FLAP, 4, 1);
        }
    }
}
 
Example 5
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gives temporary perms to players who are online when the server is reloaded or the plugin reloaded.
 */
public void giveAllTempPerms() {
    if (plugin.getGrid() == null) {
        return;
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Giving all temp perms");
    for (Player player : plugin.getServer().getOnlinePlayers()) {
        if(player != null && !player.hasMetadata("NPC") && plugin.getGrid().playerIsOnIsland(player)){
            if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")){
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Fly enable");
                player.setAllowFlight(true);
                player.setFlying(true);
            }

            for(String perm : Settings.temporaryPermissions){
                if(!VaultHelper.checkPerm(player, perm)){
                    VaultHelper.addPerm(player, perm, ASkyBlock.getIslandWorld());
                    if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                        VaultHelper.addPerm(player, perm, ASkyBlock.getNetherWorld());
                    }
                    List<String> perms = new ArrayList<String>();
                    if(temporaryPerms.containsKey(player.getUniqueId())) perms = temporaryPerms.get(player.getUniqueId());
                    perms.add(perm);
                    temporaryPerms.put(player.getUniqueId(), perms);
                }
            }
        }
    }
}
 
Example 6
Source File: EffMakeFly.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event e) {
	for (Player player : players.getArray(e)) {
		player.setAllowFlight(flying);
		player.setFlying(flying);
	}
}
 
Example 7
Source File: ExprFlightMode.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) {
	boolean state = mode != Changer.ChangeMode.RESET && delta != null && (boolean) delta[0];
	for (Player player : getExpr().getArray(event)) {
		player.setAllowFlight(state);
	}
}
 
Example 8
Source File: DGamePlayer.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
public DGamePlayer(DungeonsXL plugin, Player player, GameWorld world) {
    super(plugin, player, world);

    Game game = world.getGame();
    dGroup = (DGroup) plugin.getPlayerGroup(player);
    if (game == null) {
        game = new DGame(plugin, dGroup);
    }

    GameRuleContainer rules = game.getRules();
    player.setGameMode(GameMode.SURVIVAL);

    if (!rules.getState(GameRule.KEEP_INVENTORY_ON_ENTER)) {
        clearPlayerData();
    }
    player.setAllowFlight(rules.getState(GameRule.FLY));

    initialLives = rules.getState(GameRule.INITIAL_LIVES);
    lives = initialLives;

    resetClassInventoryOnRespawn = rules.getState(GameRule.RESET_CLASS_INVENTORY_ON_RESPAWN);

    Location teleport = world.getLobbyLocation();
    if (teleport == null) {
        player.teleport(world.getWorld().getSpawnLocation());
    } else {
        player.teleport(teleport);
    }

    if (!((DGameWorld) world).hasReadySign()) {
        MessageUtil.sendMessage(player, DMessage.ERROR_NO_READY_SIGN.getMessage(world.getName()));
    }
}
 
Example 9
Source File: PlayerStateHolder.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the default state to the player
 * and discards the current one<br><br>
 * 
 * Warning: This deletes the entire inventory
 * and all other various player attributes
 * 
 * It is recommended to save the player state
 * with {@link PlayerStateHolder#create(Player, GameMode)}
 * and store a reference to it before invoking this method
 * 
 * @param player
 */
public static void applyDefaultState(Player player, boolean adventureMode) {
	player.setGameMode(adventureMode ? GameMode.ADVENTURE : GameMode.SURVIVAL);
	player.getInventory().clear();
	player.getInventory().setArmorContents(new ItemStack[4]);
	player.setItemOnCursor(null);
	player.updateInventory();
       player.setMaxHealth(20.0);
	player.setHealth(20.0);
	player.setFoodLevel(20);
	player.setLevel(0);
	player.setExp(0f);
	player.setAllowFlight(false);
	player.setFlying(false);
	player.setFallDistance(0);
	player.setFireTicks(0);
	
	Collection<PotionEffect> effects = player.getActivePotionEffects();
	for (PotionEffect effect : effects) {
		player.removePotionEffect(effect.getType());
	}
	
	for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
		if (player.canSee(player)) {
			continue;
		}
		
		player.showPlayer(onlinePlayer);
	}
}
 
Example 10
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoinEvent(PlayerJoinEvent event)
{
	Player player = event.getPlayer();
	
	Boolean value = this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
	if (value != null)
	{
		player.setAllowFlight(value);
	}
}
 
Example 11
Source File: FlagAllowSpectateFly.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFlagRemove(Game game) {
	FlagSpectate flag = (FlagSpectate) getParent();
	Set<SpleefPlayer> spectators = flag.getSpectators();
	
	for (SpleefPlayer player : spectators) {
		Player bukkitPlayer = player.getBukkitPlayer();
		bukkitPlayer.setAllowFlight(false);
		bukkitPlayer.setFlying(false);
	}
}
 
Example 12
Source File: TutorialPlayer.java    From ServerTutorial with MIT License 5 votes vote down vote up
public void clearPlayer(Player player) {
    player.getInventory().clear();
    player.setAllowFlight(true);
    player.setFlying(true);

    player.setExp(1.0f);
    player.setLevel(0);
    player.setFoodLevel(20);
    player.setHealth(player.getMaxHealth());

    for (Player online : Bukkit.getServer().getOnlinePlayers()) {
        online.hidePlayer(player);
        player.hidePlayer(online);
    }
}
 
Example 13
Source File: StatSerializer.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Apply stats to a player.
 *
 * @param player The Player to apply the stats to.
 * @param stats  The stats to apply.
 * @param dataFormat See {@link PlayerSerializer#serialize(PWIPlayer)}.
 */
public void deserialize(Player player,JsonObject stats, int dataFormat) {
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY) && stats.has("can-fly"))
        player.setAllowFlight(stats.get("can-fly").getAsBoolean());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME) && stats.has("display-name"))
        player.setDisplayName(stats.get("display-name").getAsString());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION) && stats.has("exhaustion"))
        player.setExhaustion((float) stats.get("exhaustion").getAsDouble());
    if (settings.getProperty(PwiProperties.LOAD_EXP) && stats.has("exp"))
        player.setExp((float) stats.get("exp").getAsDouble());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && stats.has("flying") && player.getAllowFlight())
        player.setFlying(stats.get("flying").getAsBoolean());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER) && stats.has("food"))
        player.setFoodLevel(stats.get("food").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH) &&
            stats.has("max-health") &&
            stats.has("health")) {
        double maxHealth = stats.get("max-health").getAsDouble();
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
        } else {
            player.setMaxHealth(maxHealth);
        }

        double health = stats.get("health").getAsDouble();
        if (health > 0 && health <= maxHealth) {
            player.setHealth(health);
        } else {
            player.setHealth(maxHealth);
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) && stats.has("gamemode")) {
        if (stats.get("gamemode").getAsString().length() > 1) {
            player.setGameMode(GameMode.valueOf(stats.get("gamemode").getAsString()));
        } else {
            int gm = stats.get("gamemode").getAsInt();
            switch (gm) {
                case 0:
                    player.setGameMode(GameMode.CREATIVE);
                    break;
                case 1:
                    player.setGameMode(GameMode.SURVIVAL);
                    break;
                case 2:
                    player.setGameMode(GameMode.ADVENTURE);
                    break;
                case 3:
                    player.setGameMode(GameMode.SPECTATOR);
                    break;
            }
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_LEVEL) && stats.has("level"))
        player.setLevel(stats.get("level").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS) && stats.has("potion-effects")) {
        if (dataFormat < 2) {
            PotionEffectSerializer.setPotionEffects(stats.get("potion-effects").getAsString(), player);
        } else {
            PotionEffectSerializer.setPotionEffects(stats.getAsJsonArray("potion-effects"), player);
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION) && stats.has("saturation"))
        player.setSaturation((float) stats.get("saturation").getAsDouble());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE) && stats.has("fallDistance"))
        player.setFallDistance(stats.get("fallDistance").getAsFloat());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS) && stats.has("fireTicks"))
        player.setFireTicks(stats.get("fireTicks").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR) && stats.has("maxAir"))
        player.setMaximumAir(stats.get("maxAir").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR) && stats.has("remainingAir"))
        player.setRemainingAir(stats.get("remainingAir").getAsInt());
}
 
Example 14
Source File: PlayerData.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void restore(boolean playerQuit) {
if (!beingRestored) {
	beingRestored = true;
       final Player player = this.getPlayer();
       if (player == null) {
           return;
       }
       
	if (SkyWarsReloaded.getCfg().debugEnabled()) {
       	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Restoring " + player.getName());
   	}
   	PlayerStat pStats = PlayerStat.getPlayerStats(player);
       player.closeInventory();
       player.setGameMode(GameMode.SURVIVAL);
       if (SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
       	if (pStats != null) { Util.get().setPlayerExperience(player, pStats.getXp()); }
       }
       Util.get().clear(player);
       player.getInventory().clear();
       player.getInventory().setContents(inv.getContents());
       SkyWarsReloaded.getNMS().setMaxHealth(player, 20);
       if (health <= 0 || health > 20) {
		player.setHealth(20);
	} else {
		player.setHealth(health);
	}
       player.setFoodLevel(food);
       player.setSaturation(sat);
       player.resetPlayerTime();
       player.resetPlayerWeather();
       player.setAllowFlight(false);
       player.setFlying(false);
	if (!SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
		player.setExp(xp);
	}
       
       player.setFireTicks(0);
       player.setScoreboard(sb);
       if (SkyWarsReloaded.getCfg().lobbyBoardEnabled() && !SkyWarsReloaded.getCfg().bungeeMode()) {
        PlayerStat.updateScoreboard(player);
       }
       
       final Location respawn = SkyWarsReloaded.getCfg().getSpawn();
       if (SkyWarsReloaded.get().isEnabled()) {
           if (playerQuit) {
                     player.teleport(respawn, TeleportCause.END_PORTAL);
                 } else {
                     new BukkitRunnable() {
                         @Override
                         public void run() {
                             player.teleport(respawn, TeleportCause.END_PORTAL);
                         }
                     }.runTaskLater(SkyWarsReloaded.get(), 2);
                 }
	} else {
		player.teleport(respawn, TeleportCause.END_PORTAL);
	}

       
   	if (SkyWarsReloaded.getCfg().debugEnabled()) {
       	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Finished restoring " + player.getName() + ". Teleporting to Spawn");
   	}
	if (SkyWarsReloaded.getCfg().bungeeMode()) {
		new BukkitRunnable() {
			@Override
			public void run() {
				String uuid = player.getUniqueId().toString();
				SkyWarsReloaded.get().sendBungeeMsg(player, "Connect", SkyWarsReloaded.getCfg().getBungeeLobby());
				PlayerStat remove = PlayerStat.getPlayerStats(uuid);
				PlayerStat.getPlayers().remove(remove);
			}
		}.runTaskLater(SkyWarsReloaded.get(), 5);
	}
}
  }
 
Example 15
Source File: FlyKit.java    From CardinalPGM with MIT License 4 votes vote down vote up
@Override
public void remove(Player player) {
    player.setAllowFlight(false);
    player.setFlying(false);
    player.setFlySpeed(0.1f);
}
 
Example 16
Source File: DoubleJumpMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
private void refreshJump(Player player) {
  if (player.getGameMode() != GameMode.CREATIVE) {
    player.setAllowFlight(this.canJump(player));
  }
}
 
Example 17
Source File: EffToggleFlight.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (Player player : players.getArray(e))
		player.setAllowFlight(allow);
}
 
Example 18
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Removes perms for a player who was on one island and is now elsewhere
 * If fromIsland and toIsland are the same, then the player is just out of their protection zone
 * and if timing is allowed, they will keep their fly capability
 * @param player
 * @param fromIsland
 * @param toIsland
 */
public void removeTempPerms(final Player player, Island fromIsland, Island toIsland) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Removing temp perms");
    if (player == null || player.hasMetadata("NPC")) {
        return;
    }
    // Check if the player has left the island completely
    if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")) {
        // If the player has teleported to another world or island
        if (fromIsland.equals(toIsland)) {
            if (player.isFlying() && player.getGameMode().equals(GameMode.SURVIVAL)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: player is flying timer is " + Settings.flyTimeOutside + "s");
                if (Settings.flyTimeOutside == 0) {
                    player.setAllowFlight(false);
                    player.setFlying(false);
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: removed fly");
                } else {
                    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            if(!plugin.getGrid().playerIsOnIsland(player) && player.isFlying()){
                                // Check they didn't enable creative
                                if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                                    player.setAllowFlight(false);
                                    player.setFlying(false);
                                    if (DEBUG)
                                        plugin.getLogger().info("DEBUG: removed fly");
                                }
                            }

                        }
                    }, 20L*Settings.flyTimeOutside);
                }
            }
        } else {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Removing flight immediately");
            if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                // Remove fly immediately
                player.setAllowFlight(false);
                player.setFlying(false);
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: removed fly");
            }
        }
    }


    for(String perm : Settings.temporaryPermissions){
        if(temporaryPerms.containsKey(player.getUniqueId()) && VaultHelper.checkPerm(player, perm)){
            VaultHelper.removePerm(player, perm, ASkyBlock.getIslandWorld());
            if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                VaultHelper.removePerm(player, perm, ASkyBlock.getNetherWorld());
            }
            if (DEBUG)
                plugin.getLogger().info("DEBUG: removed temp perm " + perm);
            List<String> perms = temporaryPerms.get(player.getUniqueId());
            perms.remove(perm);
            if(perms.isEmpty()) temporaryPerms.remove(player.getUniqueId());
            else temporaryPerms.put(player.getUniqueId(), perms);
        }
    }
}
 
Example 19
Source File: Acrobat.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
	public void AcrobatJumpMonitor(PlayerMoveEvent event) 
	{ 
		Player player = event.getPlayer();
		if(player.getGameMode() != GameMode.CREATIVE)
		{
			if(player.isFlying())
			{
				player.setAllowFlight(false);
				player.setFlying(false);
				return;
			}
			
			if(Game.isGameRunning())
			{
				if(!player.getAllowFlight())
				{
					AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
					if(p != null && p.getKit().equals(this))
					{
						if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR && !Delays.getInstance().hasActiveDelay(player, this.getInternalName()))
						{
							//Bukkit.getLogger().info("Thing 2");
							player.setAllowFlight(true);
							return;
						}
					}
				}
			}
//			else
//			{
//				player.setAllowFlight(false);
//				player.setFlying(false);
//			}
		}
			
			
//		if(player.getGameMode() != GameMode.CREATIVE && player.isFlying())
//		{
//			player.setAllowFlight(false);
//			player.setFlying(false);
//		}
//		
//		if(Game.isGameRunning() && player.getGameMode() != GameMode.CREATIVE && !player.getAllowFlight())
//		{
//			AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
//			if(p != null && p.getKit().equals(this))
//			{
//				//This is possibly also where we would make them able to permanently sprint
//				if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR && !Delays.getInstance().hasActiveDelay(player, this.getInternalName()))
//				{
//					//Bukkit.getLogger().info("Thing 2");
//					player.setAllowFlight(true);
//					return;
//				}
//			}
//			player.setAllowFlight(false);
//			player.setFlying(false);
//		}
	}