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

The following examples show how to use org.bukkit.entity.Player#getActivePotionEffects() . 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: PlayerDeathListener.java    From PerWorldInventory with GNU General Public License v3.0 7 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 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: Game.java    From Survival-Games with GNU General Public License v3.0 6 votes vote down vote up
public void clearInv(Player p) {
	ItemStack[] inv = p.getInventory().getContents();
	for (int i = 0; i < inv.length; i++) {
		inv[i] = null;
	}
	p.getInventory().setContents(inv);
	inv = p.getInventory().getArmorContents();
	for (int i = 0; i < inv.length; i++) {
		inv[i] = null;
	}
	p.getInventory().setArmorContents(inv);
	p.updateInventory();
	for(PotionEffect e : p.getActivePotionEffects())
	{
		p.addPotionEffect(new PotionEffect(e.getType(), 0 ,0), true);
	}

}
 
Example 5
Source File: FlyOld.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
private int getJumpBoostLvl(Player p) {
    for (PotionEffect pEffect : p.getActivePotionEffects()) {
        if (pEffect.getType().equals(PotionEffectType.JUMP)) {
            return pEffect.getAmplifier() + 1;
        }
    }
    return 0;
}
 
Example 6
Source File: AcidEffect.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if player is safe from rain
 * @param player
 * @return true if they are safe
 */
private boolean isSafeFromRain(Player player) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: safe from acid rain");
    if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: wrong world");
        return true;
    }
    // Check if player has a helmet on and helmet protection is true
    if (Settings.helmetProtection && (player.getInventory().getHelmet() != null
            && player.getInventory().getHelmet().getType().name().contains("HELMET"))) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: wearing helmet.");
        return true;
    }
    // Check potions
    Collection<PotionEffect> activePotions = player.getActivePotionEffects();
    for (PotionEffect s : activePotions) {
        if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
            // Safe!
            if (DEBUG)
                plugin.getLogger().info("DEBUG: potion");
            return true;
        }
    }
    // Check if all air above player
    for (int y = player.getLocation().getBlockY() + 2; y < player.getLocation().getWorld().getMaxHeight(); y++) {
        if (!player.getLocation().getWorld().getBlockAt(player.getLocation().getBlockX(), y, player.getLocation().getBlockZ()).getType().equals(Material.AIR)) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: something other than air above player");
            return true;
        }
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: acid rain damage");
    return false;
}
 
Example 7
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(null);
    for (final PotionEffect a1 : player.getActivePotionEffects()) {
    	player.removePotionEffect(a1.getType());
    }
}
 
Example 8
Source File: GameArena.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a player to the Zombies team
 *
 * @param player the player to add
 */
public void addZombie(Player player) {
    humans.remove(player.getUniqueId());
    zombies.add(player.getUniqueId());

    // TODO: Modulairze
    player.setHealth(20D);
    player.setFireTicks(0);

    for (PotionEffect potionEffect : player.getActivePotionEffects()) {
        player.removePotionEffect(potionEffect.getType());
    }
}
 
Example 9
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 10
Source File: PWIPlayer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) {
    this.uuid = player.getUniqueId();
    this.name = player.getName();
    this.location = player.getLocation();

    this.group = group;
    this.saved = false;

    this.armor = player.getInventory().getArmorContents();
    this.enderChest = player.getEnderChest().getContents();
    this.inventory = player.getInventory().getContents();

    this.canFly = player.getAllowFlight();
    this.displayName = player.getDisplayName();
    this.exhaustion = player.getExhaustion();
    this.experience = player.getExp();
    this.isFlying = player.isFlying();
    this.foodLevel = player.getFoodLevel();
    if (useAttributes) {
        this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
    } else {
        this.maxHealth = player.getMaxHealth();
    }
    this.health = player.getHealth();
    this.gamemode = player.getGameMode();
    this.level = player.getLevel();
    this.saturationLevel = player.getSaturation();
    this.potionEffects = player.getActivePotionEffects();
    this.fallDistance = player.getFallDistance();
    this.fireTicks = player.getFireTicks();
    this.maxAir = player.getMaximumAir();
    this.remainingAir = player.getRemainingAir();

    this.bankBalance = bankBalance;
    this.balance = balance;
}
 
Example 11
Source File: ListenerPotions.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTag(PlayerTagEvent e) {
    Player player = e.getPlayer();
    Collection<PotionEffect> potionEffectList = player.getActivePotionEffects();
    for(PotionEffect potionEffect : potionEffectList) {
        if(potionEffect == null) continue;

        PotionEffectType type = potionEffect.getType();
        if(isBlocked(type)) player.removePotionEffect(type);
    }
}
 
Example 12
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 13
Source File: PlayersManager.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public void setPlayerSpectateAtLobby(UhcPlayer uhcPlayer){

		uhcPlayer.setState(PlayerState.DEAD);
		uhcPlayer.sendPrefixedMessage(Lang.PLAYERS_WELCOME_BACK_SPECTATING);

		if(GameManager.getGameManager().getConfiguration().getSpectatingTeleport()) {
			uhcPlayer.sendPrefixedMessage(Lang.COMMAND_SPECTATING_HELP);
		}

		Player player;
		try {
			player = uhcPlayer.getPlayer();player.getEquipment().clear();
			clearPlayerInventory(player);
			player.setGameMode(GameMode.SPECTATOR);
			for(PotionEffect effect : player.getActivePotionEffects())
			{
				player.removePotionEffect(effect.getType());
			}
			if(GameManager.getGameManager().getGameState().equals(GameState.DEATHMATCH)){
				player.teleport(GameManager.getGameManager().getArena().getLoc());
			}else{
				player.teleport(GameManager.getGameManager().getLobby().getLoc());
			}
		} catch (UhcPlayerNotOnlineException e) {
			// Do nothing because DEAD is a safe state
		}
	}
 
Example 14
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 15
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
public Inventory getFakeInventory(Player player, String locale) {
    Inventory inventory = Bukkit.createInventory(null, 45, player.getDisplayName().length() > 32 ? Teams.getTeamColorByPlayer(player) + player.getName() : player.getDisplayName());
    inventory.setItem(0, player.getInventory().getHelmet());
    inventory.setItem(1, player.getInventory().getChestplate());
    inventory.setItem(2, player.getInventory().getLeggings());
    inventory.setItem(3, player.getInventory().getBoots());
    inventory.setItem(4, player.getInventory().getItemInOffHand());

    ItemStack potion;
    if (player.getActivePotionEffects().size() > 0){
        ArrayList<String> effects = new ArrayList<>();
        for (PotionEffect effect : player.getActivePotionEffects()) {
            String effectName = WordUtils.capitalizeFully(effect.getType().getName().toLowerCase().replaceAll("_", " "));
            effects.add(ChatColor.YELLOW + effectName + " " + (effect.getAmplifier() + 1));
        }
        potion = Items.createItem(Material.POTION, 1, (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_POTION_EFFECTS).getMessage(locale), effects);
    } else {
        potion = Items.createItem(Material.GLASS_BOTTLE, 1, (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_POTION_EFFECTS).getMessage(locale), new ArrayList<>(Collections.singletonList(ChatColor.YELLOW + new LocalizedChatMessage(ChatConstant.UI_NO_POTION_EFFECTS).getMessage(locale))));
    }
    inventory.setItem(6, potion);
    ItemStack food = Items.createItem(Material.COOKED_BEEF, player.getFoodLevel(), (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_HUNGER_LEVEL).getMessage(locale));
    inventory.setItem(7, food);
    ItemStack health = Items.createItem(Material.REDSTONE, (int) Math.ceil(player.getHealth()), (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_HEALTH_LEVEL).getMessage(locale));
    inventory.setItem(8, health);
    for (int i = 36; i <= 44; i++) {
        inventory.setItem(i, player.getInventory().getItem(i - 36));
    }
    for (int i = 9; i <= 35; i++) {
        inventory.setItem(i, player.getInventory().getItem(i));
    }
    return inventory;
}
 
Example 16
Source File: MatchPlayer.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public void resetPotions() {
    final Player bukkit = getBukkit();
    for(PotionEffect effect : bukkit.getActivePotionEffects()) {
        if(effect.getType() != null) {
            bukkit.removePotionEffect(effect.getType());
        }
    }
}
 
Example 17
Source File: Players.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static void resetPlayer(Player player, boolean heal) {
    if (heal) player.setHealth(player.getMaxHealth());
    player.setFoodLevel(20);
    player.setSaturation(20);
    player.getInventory().clear();
    player.getInventory().setArmorContents(new ItemStack[]{new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR)});
    for (PotionEffect effect : player.getActivePotionEffects()) {
        try {
            player.removePotionEffect(effect.getType());
        } catch (NullPointerException ignored) {
        }
    }
    player.setTotalExperience(0);
    player.setExp(0);
    player.setLevel(0);
    player.setPotionParticles(false);
    player.setWalkSpeed(0.2F);
    player.setFlySpeed(0.1F);
    player.setKnockbackReduction(0);
    player.setArrowsStuck(0);

    player.hideTitle();

    player.setFastNaturalRegeneration(false);

    for (Attribute attribute : Attribute.values()) {
        if (player.getAttribute(attribute) == null) continue;
        for (AttributeModifier modifier : player.getAttribute(attribute).getModifiers()) {
            player.getAttribute(attribute).removeModifier(modifier);
        }
    }
    player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(new AttributeModifier(UUID.randomUUID(), "generic.attackSpeed", 4.001D, AttributeModifier.Operation.ADD_SCALAR));
    player.getAttribute(Attribute.ARROW_ACCURACY).addModifier(new AttributeModifier(UUID.randomUUID(), "sportbukkit.arrowAccuracy", -1D, AttributeModifier.Operation.ADD_NUMBER));
    player.getAttribute(Attribute.ARROW_VELOCITY_TRANSFER).addModifier(new AttributeModifier(UUID.randomUUID(), "sportbukkit.arrowVelocityTransfer", -1D, AttributeModifier.Operation.ADD_NUMBER));
}
 
Example 18
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 19
Source File: BlockedEffectsFlagHandler.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
private void check(Player player, ApplicableRegionSet set)
{
	Set<PotionEffectType> potionEffects = WorldGuardUtils.queryValue(player, player.getWorld(), set.getRegions(), Flags.BLOCKED_EFFECTS);
	if (potionEffects != null && potionEffects.size() > 0)
	{
		for (PotionEffectType effectType : potionEffects)
		{
			PotionEffect effect = null;
			for(PotionEffect activeEffect : player.getActivePotionEffects())
			{
				if (activeEffect.getType().equals(effectType))
				{
					effect = activeEffect;
					break;
				}
			}
			
			if (effect != null)
			{
				this.removedEffects.put(effect.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect.getAmplifier(), effect.isAmbient(), SupportedFeatures.isPotionEffectParticles() ? effect.hasParticles() : true));
				
				player.removePotionEffect(effectType);
			}
		}
	}
	
	Iterator<Entry<PotionEffectType, PotionEffectDetails>>  potionEffects_ = this.removedEffects.entrySet().iterator();
	while (potionEffects_.hasNext())
	{
		Entry<PotionEffectType, PotionEffectDetails> potionEffect = potionEffects_.next();
		
		if (potionEffects == null || !potionEffects.contains(potionEffect.getKey()))
		{
			PotionEffectDetails removedEffect = potionEffect.getValue();
			if (removedEffect != null)
			{
				int timeLeft = removedEffect.getTimeLeftInTicks();
				if (timeLeft > 0)
				{
					if (SupportedFeatures.isPotionEffectParticles())
					{
						player.addPotionEffect(new PotionEffect(potionEffect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient(), removedEffect.isParticles()), true);
					}
					else
					{
						player.addPotionEffect(new PotionEffect(potionEffect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient()), true);
					}
				}
			}
			
			potionEffects_.remove();
		}
	}
}
 
Example 20
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());
}