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

The following examples show how to use org.bukkit.entity.Player#setFlying() . 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: DoubleJump.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onJump(PlayerToggleFlightEvent event) {
    Player player = event.getPlayer();
    if (player.getGameMode() == GameMode.CREATIVE) return;
    if (!isEnabledInWorld(player.getWorld())) return;

    Section section = getWorldConfiguration(player.getWorld().getName());

    event.setCancelled(true);
    player.setAllowFlight(false);
    player.setFlying(false);
    Sound sound = FinderUtil.findSound(section.getString("Sound", "NOPE"));
    player.setVelocity(player.getLocation().getDirection().multiply(section.getDouble("Force", 1.0)).setY(1));
    if (sound != null) {
        player.playSound(player.getLocation(), sound, 1.0F, -5.0F);
    }
}
 
Example 2
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 3
Source File: ListenerFlight.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTag(PlayerTagEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("flight.prevent-flying")) return;

    Player player = e.getPlayer();
    if(!player.isFlying()) return;

    player.setFlying(false);
    if(config.getBoolean("flight.force-disable-flight")) player.setAllowFlight(false);
    
    UUID uuid = player.getUniqueId();
    this.preventFallDamage.add(uuid);

    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.flight.force-disabled");
    this.plugin.sendMessage(player, message);
}
 
Example 4
Source File: PlayerJoinLeaveListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onJoin(PlayerJoinEvent event) {
    try {
        final Player player = event.getPlayer();
        final IridiumSkyblock plugin = IridiumSkyblock.getInstance();
        if (player.isOp()) {
            final String latest = plugin.getLatest();
            if (plugin.getLatest() != null
                    && IridiumSkyblock.getConfiguration().notifyAvailableUpdate
                    && !latest.equals(plugin.getDescription().getVersion())) {
                final String prefix = IridiumSkyblock.getConfiguration().prefix;
                player.sendMessage(Utils.color(prefix + " &7This message is only seen by opped players."));
                player.sendMessage(Utils.color(prefix + " &7Newer version available: " + latest));
            }
        }

        final Location location = player.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        final User user = User.getUser(player);
        user.name = player.getName();

        if (user.flying && (user.getIsland() == null || user.getIsland().getFlightBooster() == 0)) {
            player.setAllowFlight(false);
            player.setFlying(false);
            user.flying = false;
        }
        user.bypassing = false;

        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        Bukkit.getScheduler().runTaskLater(plugin, () -> island.sendBorder(player), 1);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 5
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 6
Source File: FlagAllowSpectateFly.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public void setValue(Boolean value) {
	super.setValue(value);
	
	FlagSpectate flag = (FlagSpectate) getParent();
	
	if (flag != null) {
		Set<SpleefPlayer> spectators = flag.getSpectators();
		
		for (SpleefPlayer player : spectators) {
			Player bukkitPlayer = player.getBukkitPlayer();
			bukkitPlayer.setAllowFlight(value);
			bukkitPlayer.setFlying(value);
		}
	}
}
 
Example 7
Source File: MatchPlayer.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public void reset() {
    final Player bukkit = getBukkit();
    bukkit.closeInventory();
    clearInventory();
    bukkit.setExhaustion(0);
    bukkit.setFallDistance(0);
    bukkit.setFireTicks(0);
    bukkit.setFoodLevel(20); // full
    bukkit.setMaxHealth(20);
    bukkit.setHealth(bukkit.getMaxHealth());
    bukkit.setAbsorption(0);
    bukkit.setLevel(0);
    bukkit.setExp(0); // clear xp
    bukkit.setSaturation(5); // default
    bukkit.setFastNaturalRegeneration(false);
    bukkit.setSlowNaturalRegeneration(true);
    bukkit.setAllowFlight(false);
    bukkit.setFlying(false);
    bukkit.setSneaking(false);
    bukkit.setSprinting(false);
    bukkit.setFlySpeed(0.1f);
    bukkit.setKnockbackReduction(0);
    bukkit.setWalkSpeed(WalkSpeedKit.BUKKIT_DEFAULT);
    AttributeUtils.removeAllModifiers(bukkit);
    resetPotions();

    // we only reset bed spawn here so people don't have to see annoying messages when they respawn
    bukkit.setBedSpawnLocation(null);

    match.callEvent(new PlayerResetEvent(this));
}
 
Example 8
Source File: FlagAllowSpectateFly.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public void spectateEnter(SpleefPlayer spleefPlayer) {		
	boolean value = getValue();
	Player player = spleefPlayer.getBukkitPlayer();
	
	player.setAllowFlight(value);
	player.setFlying(value);
}
 
Example 9
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 10
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 11
Source File: FlyCommand.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
    Player p = (Player) sender;
    User user = User.getUser(p);
    if (user.getIsland() != null) {
        if (user.getIsland().isInIsland(p.getLocation())) {
            if (user.getIsland().getFlightBooster() != 0 || p.hasPermission("iridiumskyblock.Fly")) {
                if (p.getAllowFlight()) {
                    p.setAllowFlight(false);
                    p.setFlying(false);
                    p.sendMessage(Utils.color(IridiumSkyblock.getMessages().flightDisabled.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                } else {
                    p.setAllowFlight(true);
                    p.setFlying(true);
                    p.sendMessage(Utils.color(IridiumSkyblock.getMessages().flightEnabled.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
                user.flying = p.isFlying();
            } else {
                p.sendMessage(Utils.color(IridiumSkyblock.getMessages().flightBoosterNotActive.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        } else {
            p.sendMessage(Utils.color(IridiumSkyblock.getMessages().mustBeInIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
        }
    } else {
        p.sendMessage(Utils.color(IridiumSkyblock.getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
    }
}
 
Example 12
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 13
Source File: CombatTag.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
    public void onDamage(EntityDamageByEntityEvent event) {

        Player player = playerFinder(event);

        if (player == null) return;

        if (player.getGameMode().equals(GameMode.CREATIVE)) return;

        if (player.isInvulnerable()) player.setInvulnerable(false);
        if (player.isFlying()) {
            player.setFlying(false);
            player.spigot().sendMessage(ChatMessageType.ACTION_BAR,
                    TextComponent.fromLegacyText(ChatColorConverter.convert(ConfigValues.combatTagConfig.getString(CombatTagConfig.COMBAT_TAG_MESSAGE))));
            new BukkitRunnable() {
                @Override
                public void run() {
                    //TODO: introduce the featherfall potion effect for versions above 1.12.2
//                    if (NameHandler.currentVersionIsUnder(13, 0)) {
                    if (!player.isOnline() || player.isDead())
                        cancel();
                    if (player.isOnGround()) {
                        player.setFallDistance(0F);
                        cancel();
                    }
//                    } else {
////TODO: introduce the featherfall potion effect for versions above 1.12.2
//                        if (!player.isOnline() || player.isDead())
//                            player.removePotionEffect(PotionEffectType.SLOW);
//                            cancel();
//                        if (player.isOnGround()) {
//                            player.setFallDistance(0F);
//                            cancel();
//                        }
//
//                    }
                }
            }.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);
        }
    }
 
Example 14
Source File: FlyKit.java    From CardinalPGM with MIT License 4 votes vote down vote up
@Override
public void apply(Player player, Boolean force) {
    player.setAllowFlight(canFly);
    if (flying != null) player.setFlying(flying);
    player.setFlySpeed(flySpeed);
}
 
Example 15
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 16
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);
//		}
	}
 
Example 17
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 18
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 19
Source File: CommonEntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
    if (user == null) {
        return;
    }
    final Player player = user.getOnlinePlayer();
    if (player == null || !player.isFlying()) {
        // Most likely Citizens NPC
        return;
    }
    if (!GDOptions.isOptionEnabled(Options.PLAYER_DENY_FLIGHT)) {
        return;
    }

    final GDPlayerData playerData = user.getInternalPlayerData();
    final GameMode gameMode = player.getGameMode();
    if (gameMode == GameMode.SPECTATOR) {
        return;
    }
    if (gameMode == GameMode.CREATIVE) {
        if (playerData.inPvpCombat() && !GriefDefenderPlugin.getActiveConfig(player.getWorld().getUID()).getConfig().pvp.allowFly) {
            player.setAllowFlight(false);
            player.setFlying(false);
            playerData.ignoreFallDamage = true;
            GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_FLIGHT);
            return;
        }
        return;
    }

    final Boolean noFly = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Boolean.class), playerData.getSubject(), Options.PLAYER_DENY_FLIGHT, toClaim);
    final boolean adminFly = playerData.userOptionBypassPlayerDenyFlight;
    boolean trustFly = false;
    if (toClaim.isBasicClaim() || (toClaim.parent != null && toClaim.parent.isBasicClaim()) || toClaim.isInTown()) {
        // check owner
        if (playerData.userOptionPerkFlyOwner && toClaim.allowEdit(player) == null) {
            trustFly = true;
        } else {
            if (playerData.userOptionPerkFlyAccessor && toClaim.isUserTrusted(player, TrustTypes.ACCESSOR)) {
                trustFly = true;
            } else if (playerData.userOptionPerkFlyBuilder && toClaim.isUserTrusted(player, TrustTypes.BUILDER)) {
                trustFly = true;
            } else if (playerData.userOptionPerkFlyContainer && toClaim.isUserTrusted(player, TrustTypes.CONTAINER)) {
                trustFly = true;
            } else if (playerData.userOptionPerkFlyManager && toClaim.isUserTrusted(player, TrustTypes.MANAGER)) {
                trustFly = true;
            }
         }
    }

    if (trustFly) {
        return;
    }
    if (!adminFly && noFly) {
        player.setAllowFlight(false);
        player.setFlying(false);
        playerData.ignoreFallDamage = true;
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_FLIGHT);
    }
}
 
Example 20
Source File: PlayerStateHolder.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public void apply(Player player, boolean teleport) {
	PlayerInventory playerInv = player.getInventory();
	boolean is1_9 = MinecraftVersion.getImplementationVersion().compareTo(MinecraftVersion.V1_9) >= 0;
       boolean isSimpleSize = playerInv.getContents().length <= SIMPLE_INVENTORY_SIZE;

       ItemStack[] inventoryContents = new ItemStack[is1_9 && !isSimpleSize ? playerInv.getSize() : SIMPLE_INVENTORY_SIZE];
       System.arraycopy(inventory, 0, inventoryContents, 0, inventoryContents.length);

       if (!is1_9 || isSimpleSize) {
           ItemStack[] armorContents = new ItemStack[ARMOR_INVENTORY_SIZE];
           System.arraycopy(inventory, inventory.length - ARMOR_INVENTORY_SIZE, armorContents, 0, armorContents.length);
           playerInv.setArmorContents(armorContents);
       }
	
	playerInv.setContents(inventoryContents);

	player.setItemOnCursor(null);
	Map<Integer, ItemStack> exceeded = playerInv.addItem(onCursor);
	for (ItemStack stack : exceeded.values()) {
           if (stack.getType() == Material.AIR) {
               continue;
           }
           
		player.getWorld().dropItem(player.getLocation(), stack);
	}
	
	player.updateInventory();

       player.setMaxHealth(maxHealth);
	player.setHealth(health);
	player.setFoodLevel(foodLevel);
	player.setLevel(level);
	player.setExp(experience);
	player.setAllowFlight(allowFlight);
	player.setFlying(isFlying);
	
	/* Remove current potion effects */
	Collection<PotionEffect> effects = player.getActivePotionEffects();
	for (PotionEffect effect : effects) {
		player.removePotionEffect(effect.getType());
	}
	player.addPotionEffects(activeEffects);
	
	player.setExhaustion(exhaustion);
	player.setSaturation(saturation);
	player.setFallDistance(fallDistance);
	player.setFireTicks(fireTicks);
	
	if (scoreboard != player.getScoreboard()) {
		Scoreboard showBoard = scoreboard;
		if (scoreboard == null) {
			showBoard = Bukkit.getScoreboardManager().getMainScoreboard();
		}
		
		player.setScoreboard(showBoard);
	}
	
	if (teleport) {
		player.teleport(location);
	}
	
	Location compassTarget = this.compassTarget;
	
	if (compassTarget == null) {
		compassTarget = player.getWorld().getSpawnLocation();
	}
	
	player.setCompassTarget(compassTarget);
	
	for (WeakReference<Player> ref : cantSee) {
		Player cantSeePlayer = ref.get();
		
		if (cantSeePlayer == null) {
			// Player object has been garbage-collected
			continue;
		}
		
		if (!cantSeePlayer.isOnline()) {
			continue;
		}
		
		player.hidePlayer(cantSeePlayer);
	}
	
	player.setGameMode(gamemode);
}