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

The following examples show how to use org.bukkit.entity.Player#removePotionEffect() . 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: PlayerDeathListener.java    From PerWorldInventory with GNU General Public License v3.0 8 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) {
    Player player = event.getEntity();
    Group group = groupManager.getGroupFromWorld(player.getLocation().getWorld().getName());

    if (!event.getKeepInventory()) {
        player.getInventory().clear();
    }

    if (!event.getKeepLevel()) {
        player.setExp(event.getNewExp());
        player.setLevel(event.getNewLevel());
    }

    player.setFoodLevel(20);
    player.setSaturation(5f);
    player.setExhaustion(0f);
    player.setFallDistance(0f);
    player.setFireTicks(0);
    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }

    playerManager.addPlayer(player, group);
}
 
Example 2
Source File: Scotopic.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onMoveImmune(PlayerMoveEvent event) {
	if (!this.givesImmunity) return;

	Player player = event.getPlayer();
	if (!player.hasPermission("minetinker.modifiers.scotopic.use")) {
		return;
	}

	ItemStack armor = player.getInventory().getHelmet();
	if (armor == null) return;

	if (!modManager.hasMod(armor, this)) return;
	if (player.hasPotionEffect(PotionEffectType.BLINDNESS)) {
		player.removePotionEffect(PotionEffectType.BLINDNESS);
		ChatWriter.logModifier(player, event, this, armor, "RemoveBlindness");
	}
}
 
Example 3
Source File: PluginMain.java    From PlayerSQL with GNU General Public License v2.0 6 votes vote down vote up
public static void resetPlayerState(Player player) {
    if (Config.SYN_INVENTORY) {
        player.getInventory().clear();
    }
    if (Config.SYN_HEALTH) {
        player.resetMaxHealth();
        player.setHealth(player.getMaxHealth());
    }
    if (Config.SYN_EXP) {
        SetExpFix.setTotalExperience(player, 0);
    }
    if (Config.SYN_FOOD) {
        player.setFoodLevel(20);
    }
    if (Config.SYN_EFFECT) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
    }
    if (Config.SYN_CHEST) {
        player.getEnderChest().clear();
    }
}
 
Example 4
Source File: Assassin.java    From AnnihilationPro with MIT License 6 votes vote down vote up
private void endLeap(Player player, AnniPlayer p)
{
	if(p.getData("Cur") != null)
	{
		Object obj = p.getData("Arm");
		if(obj != null && player != null)
			player.getInventory().setArmorContents((ItemStack[])obj);
		p.setData("Arm", null);
		if(player != null)
		{
			player.removePotionEffect(PotionEffectType.INVISIBILITY);
			player.removePotionEffect(PotionEffectType.SPEED);
			player.removePotionEffect(PotionEffectType.FAST_DIGGING);
		}
		p.setData("Cur", null);
	}
}
 
Example 5
Source File: TeleportPlayersThread.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
	
	for(UhcPlayer uhcPlayer : team.getMembers()){
		Player player;
		try {
			player = uhcPlayer.getPlayer();
		}catch (UhcPlayerNotOnlineException ex){
			continue;
		}

		Bukkit.getLogger().info("[UhcCore] Teleporting "+player.getName());

		for(PotionEffect effect : GameManager.getGameManager().getConfiguration().getPotionEffectOnStart()){
			player.addPotionEffect(effect);
		}

		uhcPlayer.freezePlayer(team.getStartingLocation());
		player.teleport(team.getStartingLocation());
		player.removePotionEffect(PotionEffectType.BLINDNESS);
		player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
		player.setFireTicks(0);
		uhcPlayer.setHasBeenTeleportedToLocation(true);
	}
}
 
Example 6
Source File: FlagInvisibleSpectate.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Subscribe
public void onSpectateLeave(FlagSpectate.SpectateLeaveEvent event) {
	SpleefPlayer player = event.getPlayer();
	Player bukkitPlayer = player.getBukkitPlayer();
	
	team.removePlayer(bukkitPlayer);
	bukkitPlayer.removePotionEffect(PotionEffectType.INVISIBILITY);
	
	for (SpleefPlayer ingamePlayer : game.getPlayers()) {
		if (ingamePlayer.getBukkitPlayer().canSee(bukkitPlayer)) {
			continue;
		}
		
		ingamePlayer.getBukkitPlayer().showPlayer(bukkitPlayer);
	}
	
	Scoreboard mainScoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
	bukkitPlayer.setScoreboard(mainScoreboard);
}
 
Example 7
Source File: Webbed.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onMove(PlayerMoveEvent event) {
	if (!this.givesImmunity) return;

	Player player = event.getPlayer();
	if (!player.hasPermission("minetinker.modifiers.webbed.use")) {
		return;
	}

	boolean hasWebbed = false;
	ItemStack armor = null;
	for (ItemStack stack : player.getInventory().getArmorContents()) {
		if (stack == null) continue;
		if (modManager.hasMod(stack, this)) {
			hasWebbed = true;
			armor = stack;
			break;
		}
	}

	if (!hasWebbed) return;
	if (player.hasPotionEffect(PotionEffectType.SLOW)) {
		player.removePotionEffect(PotionEffectType.SLOW);
		ChatWriter.logModifier(player, event, this, armor, "RemoveEffect");
	}
}
 
Example 8
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void clear(final Player player) {
    player.getInventory().clear();
    player.getInventory().setArmorContents((ItemStack[])null);
    for (final PotionEffect a1 : player.getActivePotionEffects()) {
    	player.removePotionEffect(a1.getType());
    }
}
 
Example 9
Source File: PlayersManager.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public void setPlayerStartPlaying(UhcPlayer uhcPlayer){

		Player player;
		MainConfiguration cfg = GameManager.getGameManager().getConfiguration();

		if(!uhcPlayer.getHasBeenTeleportedToLocation()){
			uhcPlayer.setState(PlayerState.PLAYING);
			uhcPlayer.selectDefaultGlobalChat();

			try {
				player = uhcPlayer.getPlayer();
				clearPlayerInventory(player);
				player.setFireTicks(0);

				for(PotionEffect effect : player.getActivePotionEffects())
				{
					player.removePotionEffect(effect.getType());
				}
				player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 999999, 1), false);
				player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 999999, 40), false);
				player.setGameMode(GameMode.SURVIVAL);
				if(cfg.getEnableExtraHalfHearts()){
					VersionUtils.getVersionUtils().setPlayerMaxHealth(player, 20+((double) cfg.getExtraHalfHearts()));
					player.setHealth(20+((double) cfg.getExtraHalfHearts()));
				}
				UhcItems.giveGameItemTo(player, GameItem.COMPASS_ITEM);
				UhcItems.giveGameItemTo(player, GameItem.CUSTOM_CRAFT_BOOK);
				KitsManager.giveKitTo(player);

				if (!uhcPlayer.getStoredItems().isEmpty()){
					player.getInventory().addItem(uhcPlayer.getStoredItems().toArray(new ItemStack[]{}));
					uhcPlayer.getStoredItems().clear();
				}
			} catch (UhcPlayerNotOnlineException e) {
				// Nothing done
			}
		}
	}
 
Example 10
Source File: AssassinsBlade.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean effect(Event event, final Player player) {
	if(event instanceof PlayerInteractEvent) {
		if(!player.hasMetadata("ce.assassin"))
			if(player.isSneaking())
					  player.setMetadata("ce.assassin", new FixedMetadataValue(main, null));
					  player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, InvisibilityDuration, 0, true), true);
					  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You hide in the shadows.");
					  new BukkitRunnable() {
						  @Override
						  public void run() {
							  if(player.hasMetadata("ce.assassin")) {
								  player.removeMetadata("ce.assassin", main);
								  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You are no longer hidden!");
							  }
						  }
					  }.runTaskLater(main, InvisibilityDuration);
					  return true;
				  }
	if(event instanceof EntityDamageByEntityEvent) {
		EntityDamageByEntityEvent e = ((EntityDamageByEntityEvent) event);
		if(e.getDamager() == player && player.hasMetadata("ce.assassin")) {
			  e.setDamage(e.getDamage() * AmbushDmgMultiplier);
			  player.removeMetadata("ce.assassin", main);
			  player.removePotionEffect(PotionEffectType.INVISIBILITY);
			  EffectManager.playSound(e.getEntity().getLocation(), "BLOCK_PISTON_EXTEND", 0.4f, 0.1f);
			  player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, WeaknessLength, WeaknessLevel, false), true);
			  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You are no longer hidden!");
	   }
	}
	 return false;
}
 
Example 11
Source File: FlagFreeze.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
private void unfreezePlayer(SpleefPlayer player) {
	task.removeFrozenPlayer(player);
	
	Player bukkitPlayer = player.getBukkitPlayer();
	bukkitPlayer.setWalkSpeed(DEFAULT_WALK_SPEED);
	bukkitPlayer.removePotionEffect(PotionEffectType.JUMP);
}
 
Example 12
Source File: Utils.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a player's stats to defaults, and optionally clear their inventory.
 *
 * @param plugin {@link PerWorldInventory} for econ.
 * @param player The player to zero.
 * @param clearInventory Clear the player's inventory.
 */
public static void zeroPlayer(PerWorldInventory plugin, Player player, boolean clearInventory) {
    if (clearInventory) {
        player.getInventory().clear();
        player.getEnderChest().clear();
    }

    player.setExp(0f);
    player.setFoodLevel(20);

    if (checkServerVersion(Bukkit.getVersion(), 1, 9, 0)) {
        player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
    } else {
        player.setHealth(player.getMaxHealth());
    }

    player.setLevel(0);
    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }
    player.setSaturation(5f);
    player.setFallDistance(0f);
    player.setFireTicks(0);

    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        econ.withdrawPlayer(player, econ.getBalance(player));
    }
}
 
Example 13
Source File: Utils.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a player's stats to defaults, and optionally clear their inventory.
 *
 * @param plugin {@link PerWorldInventory} for econ.
 * @param player The player to zero.
 * @param clearInventory Clear the player's inventory.
 */
public static void zeroPlayer(PerWorldInventory plugin, Player player, boolean clearInventory) {
    if (clearInventory) {
        player.getInventory().clear();
        player.getEnderChest().clear();
    }

    player.setExp(0f);
    player.setFoodLevel(20);

    if (checkServerVersion(Bukkit.getVersion(), 1, 9, 0)) {
        player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
    } else {
        player.setHealth(player.getMaxHealth());
    }

    player.setLevel(0);
    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }
    player.setSaturation(5f);
    player.setFallDistance(0f);
    player.setFireTicks(0);

    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        econ.withdrawPlayer(player, econ.getBalance(player));
    }
}
 
Example 14
Source File: SpectatorTools.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    ItemStack item = event.getCurrentItem();
    Player player = (Player) event.getWhoClicked();
    String locale = player.getLocale();
    if (item == null) return;
    if (event.getInventory().getName().equals(getSpectatorMenuTitle(event.getActor().getLocale()))) {
        if (item.isSimilar(getTeleportItem(locale))) {
            player.openInventory(getTeamsMenu(player));
        } else if (item.isSimilar(getVisibilityItem(locale))) {
            Bukkit.dispatchCommand(player, "toggle obs");
            player.closeInventory();
        } else if (item.isSimilar(getElytraItem(locale))) {
            Bukkit.dispatchCommand(player, "toggle elytra");
            player.closeInventory();
        } else if (item.isSimilar(getEffectsItem(locale))) {
            player.openInventory(getEffectsMenu(player));
        } else if (item.isSimilar(getGamemodeItem(locale))) {
            player.setGameMode(player.getGameMode().equals(GameMode.CREATIVE) ? GameMode.SPECTATOR : GameMode.CREATIVE);
            if (player.getGameMode().equals(GameMode.CREATIVE)) Bukkit.dispatchCommand(player, "!");
            player.closeInventory();
        }
    } else if (event.getInventory().getName().equals(getTeamsMenuTitle(locale))) {
        if (item.isSimilar(getGoBackItem(locale))) {
            player.openInventory(getSpectatorMenu(player));
        } else if (item.getType().equals(Material.LEATHER_HELMET) && item.getItemMeta().hasDisplayName() && !item.isSimilar(TeamPicker.getTeamPicker(locale))){
            TeamModule team = Teams.getTeamByName(ChatColor.stripColor(Strings.removeLastWord(item.getItemMeta().getDisplayName()))).orNull();
            if (team != null) {
                player.openInventory(getTeleportMenu(player, team));
            }
        }
    } else if (event.getInventory().getName().equals(getTeleportMenuTitle(locale))) {
        if (item.isSimilar(getGoBackItem(locale))) {
            player.openInventory(getTeamsMenu(player));
        } else if (item.getType().equals(Material.SKULL_ITEM) && item.getItemMeta().hasDisplayName()) {
            Player teleport = Bukkit.getPlayer(((SkullMeta) item.getItemMeta()).getOwner());
            if (teleport != null) {
                player.teleport(teleport);
                player.closeInventory();
            }
        }
    } else if (event.getInventory().getName().equals(getEffectsMenuTitle(locale))) {
        if (item.isSimilar(getGoBackItem(locale))) {
            player.openInventory(getSpectatorMenu(player));
        } else if (item.isSimilar(getNightVisionItem(player.getLocale()))) {
            if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
                player.removePotionEffect(PotionEffectType.NIGHT_VISION);
            } else {
                player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, false, false));
            }
            player.closeInventory();
        } else if (item.getType().equals(Material.SUGAR) && item.getItemMeta().hasDisplayName()) {
            int value = event.getSlot();
            Setting setting = Settings.getSettingByName("Speed");
            Bukkit.dispatchCommand(player, "set speed " + setting.getValues().get(value).getValue());
            player.closeInventory();
        }
    }
}
 
Example 15
Source File: PotionKit.java    From CardinalPGM with MIT License 4 votes vote down vote up
@Override
public void remove(Player player) {
    for(PotionEffect effect : effects) player.removePotionEffect(effect.getType());
}
 
Example 16
Source File: MatchPlayerImpl.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void reset() {
  getMatch().callEvent(new PlayerResetEvent(this));

  setFrozen(false);
  Player bukkit = getBukkit();
  bukkit.closeInventory();
  resetInventory();
  bukkit.setArrowsStuck(0);
  bukkit.setExhaustion(0);
  bukkit.setFallDistance(0);
  bukkit.setFireTicks(0);
  bukkit.setFoodLevel(20); // full
  bukkit.setHealth(bukkit.getMaxHealth());
  bukkit.setLevel(0);
  bukkit.setExp(0); // clear xp
  bukkit.setSaturation(5); // default
  bukkit.setAllowFlight(false);
  bukkit.setFlying(false);
  bukkit.setSneaking(false);
  bukkit.setSprinting(false);
  bukkit.setFlySpeed(0.1f);
  bukkit.setKnockbackReduction(0);
  bukkit.setWalkSpeed(WalkSpeedKit.BUKKIT_DEFAULT);

  for (PotionEffect effect : bukkit.getActivePotionEffects()) {
    if (effect.getType() != null) {
      bukkit.removePotionEffect(effect.getType());
    }
  }

  for (Attribute attribute : ATTRIBUTES) {
    AttributeInstance attributes = bukkit.getAttribute(attribute);
    if (attributes == null) continue;

    for (AttributeModifier modifier : attributes.getModifiers()) {
      attributes.removeModifier(modifier);
    }
  }

  NMSHacks.setAbsorption(bukkit, 0);

  // we only reset bed spawn here so people don't have to see annoying messages when they respawn
  bukkit.setBedSpawnLocation(null);
}
 
Example 17
Source File: ASkyBlock.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resets a player's inventory, armor slots, equipment, enderchest and
 * potion effects
 *
 * @param player - player
 */
@SuppressWarnings("deprecation")
public void resetPlayer(Player player) {
    // getLogger().info("DEBUG: clear inventory = " +
    // Settings.clearInventory);
    if (Settings.clearInventory
            && (player.getWorld().getName().equalsIgnoreCase(Settings.worldName) || player.getWorld().getName()
                    .equalsIgnoreCase(Settings.worldName + "_nether"))) {
        // Clear their inventory and equipment and set them as survival
        player.getInventory().clear(); // Javadocs are wrong - this does not
        // clear armor slots! So...
        player.getInventory().setArmorContents(null);
        player.getInventory().setHelmet(null);
        player.getInventory().setChestplate(null);
        player.getInventory().setLeggings(null);
        player.getInventory().setBoots(null);
        player.getEquipment().clear();
    }
    if (!player.isOp()) {
        player.setGameMode(GameMode.SURVIVAL);
    }
    if (Settings.resetChallenges) {
        // Reset the player's challenge status
        players.resetAllChallenges(player.getUniqueId(), false);
    }
    // Reset the island level
    players.setIslandLevel(player.getUniqueId(), 0);
    // Clear the starter island
    players.clearStartIslandRating(player.getUniqueId());
    // Save the player
    players.save(player.getUniqueId());
    topTen.topTenAddEntry(player.getUniqueId(), 0);
    // Update the inventory
    player.updateInventory();
    if (Settings.resetEnderChest) {
        // Clear any Enderchest contents
        final ItemStack[] items = new ItemStack[player.getEnderChest().getContents().length];
        player.getEnderChest().setContents(items);
    }
    // Clear any potion effects
    for (PotionEffect effect : player.getActivePotionEffects())
        player.removePotionEffect(effect.getType());
}
 
Example 18
Source File: ProcessSyncPlayerLogin.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Performs operations in sync mode for a player that has just logged in.
 *
 * @param player the player that was logged in
 * @param isFirstLogin true if this is the first time the player logged in
 * @param authsWithSameIp registered names with the same IP address as the player's
 */
public void processPlayerLogin(Player player, boolean isFirstLogin, List<String> authsWithSameIp) {
    final String name = player.getName().toLowerCase();
    final LimboPlayer limbo = limboService.getLimboPlayer(name);

    // Limbo contains the State of the Player before /login
    if (limbo != null) {
        limboService.restoreData(player);
    }

    if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
        restoreInventory(player);
    }

    final PlayerAuth auth = playerCache.getAuth(name);
    teleportationService.teleportOnLogin(player, auth, limbo);

    // We can now display the join message (if delayed)
    joinMessageService.sendMessage(name);

    if (commonService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
        player.removePotionEffect(PotionEffectType.BLINDNESS);
    }

    // The Login event now fires (as intended) after everything is processed
    bukkitService.callEvent(new LoginEvent(player));

    // Login is done, display welcome message
    welcomeMessageConfiguration.sendWelcomeMessage(player);

    // Login is now finished; we can force all commands
    if (isFirstLogin) {
        commandManager.runCommandsOnFirstLogin(player, authsWithSameIp);
    }
    commandManager.runCommandsOnLogin(player, authsWithSameIp);

    if (!permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_BUNGEE_SEND)) {
        // Send Bungee stuff. The service will check if it is enabled or not.
        bungeeSender.connectPlayerOnLogin(player);
    }
}
 
Example 19
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get a player from the cache, and apply the cached inventories and stats
 * to the actual player. If no matching player is found in the cache, nothing
 * happens and this method simply returns.
 *
 * @param group The {@link Group} the cached player was in.
 * @param gamemode The GameMode the cached player was in.
 * @param player The current actual player to apply the data to.
 * @param cause What triggered the inventory switch; passed on for post-processing.
 */
private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) {
    PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId());
    if (cachedPlayer == null) {
        ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache");

        return;
    }

    ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data");

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS))
        player.getEnderChest().setContents(cachedPlayer.getEnderChest());
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) {
        player.getInventory().setContents(cachedPlayer.getInventory());
        player.getInventory().setArmorContents(cachedPlayer.getArmor());
    }
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY))
        player.setAllowFlight(cachedPlayer.getCanFly());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME))
        player.setDisplayName(cachedPlayer.getDisplayName());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION))
        player.setExhaustion(cachedPlayer.getExhaustion());
    if (settings.getProperty(PwiProperties.LOAD_EXP))
        player.setExp(cachedPlayer.getExperience());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight())
        player.setFlying(cachedPlayer.isFlying());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER))
        player.setFoodLevel(cachedPlayer.getFoodLevel());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH)) {
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth());
        } else {
            player.setMaxHealth(cachedPlayer.getMaxHealth());
        }
        if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) {
            player.setHealth(cachedPlayer.getHealth());
        } else {
            player.setHealth(cachedPlayer.getMaxHealth());
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)))
        player.setGameMode(cachedPlayer.getGamemode());
    if (settings.getProperty(PwiProperties.LOAD_LEVEL))
        player.setLevel(cachedPlayer.getLevel());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
        player.addPotionEffects(cachedPlayer.getPotionEffects());
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION))
        player.setSaturation(cachedPlayer.getSaturationLevel());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE))
        player.setFallDistance(cachedPlayer.getFallDistance());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS))
        player.setFireTicks(cachedPlayer.getFireTicks());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR))
        player.setMaximumAir(cachedPlayer.getMaxAir());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR))
        player.setRemainingAir(cachedPlayer.getRemainingAir());
    if (settings.getProperty(PwiProperties.USE_ECONOMY)) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (er.transactionSuccess()) {
            econ.depositPlayer(player, cachedPlayer.getBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage);
        }

        EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        if (bankER.transactionSuccess()) {
            econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage);
        }
    }

    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    Bukkit.getPluginManager().callEvent(event);
}
 
Example 20
Source File: PotionEffectApplier.java    From EliteMobs with GNU General Public License v3.0 2 votes vote down vote up
private void continuousPotionEffectApplier(HashMap<PotionEffect, List<String>> potionEffects, Player
        player) {

    for (PotionEffect potionEffect : potionEffects.keySet()) {

        if (potionEffects.get(potionEffect).size() > 0) {

            if (potionEffects.get(potionEffect).get(0).equalsIgnoreCase(SELF)) {

                if ((!offensivePotionEffects.contains(potionEffect.getType()) && potionEffects.get(potionEffect).size() == 1) ||
                        (!offensivePotionEffects.contains(potionEffect.getType()) && potionEffects.get(potionEffect).get(1).equalsIgnoreCase(CONTINUOUS))) {

                    player.removePotionEffect(potionEffect.getType());
                    player.addPotionEffect(potionEffect);

                }

                if (offensivePotionEffects.contains(potionEffect.getType()) && potionEffects.get(potionEffect).size() > 1) {

                    if (potionEffects.get(potionEffect).get(1).equalsIgnoreCase(CONTINUOUS)) {

                        player.removePotionEffect(potionEffect.getType());
                        player.addPotionEffect(potionEffect);

                    }

                }


            } else if (potionEffects.get(potionEffect).get(0).equalsIgnoreCase(TARGET)) {

                //this doesn't do anything since this will only continuously apply to the player.

            }

        } else {

            //legacy config settings where there are no tags
            if (!offensivePotionEffects.contains(potionEffect.getType())) {

                player.removePotionEffect(potionEffect.getType());
                player.addPotionEffect(potionEffect);

            }

        }

    }

}