Java Code Examples for org.bukkit.entity.Player#addPotionEffect()
The following examples show how to use
org.bukkit.entity.Player#addPotionEffect() .
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: Game.java From Survival-Games with GNU General Public License v3.0 | 6 votes |
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 2
Source File: Vitamins.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public ItemUseHandler getItemHandler() { return e -> { Player p = e.getPlayer(); if (p.getGameMode() != GameMode.CREATIVE) { ItemUtils.consumeItem(e.getItem(), false); } p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1); if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON); if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER); if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW); if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING); if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS); if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION); if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS); p.setFireTicks(0); p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 2)); e.cancel(); }; }
Example 3
Source File: FeatureEmulation.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler public void onPotionEffectAdd(EntityPotionEffectEvent event) { if (!(event.getEntity() instanceof Player)) { return; } Player player = (Player) event.getEntity(); PotionEffect effect = event.getNewEffect(); if (effect != null) { int amplifierByte = (byte) effect.getAmplifier(); if (effect.getAmplifier() != amplifierByte) { event.setCancelled(true); player.addPotionEffect(new PotionEffect( effect.getType(), effect.getDuration(), amplifierByte, effect.isAmbient(), effect.hasParticles(), effect.hasIcon() )); } } }
Example 4
Source File: FlagFreeze.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
private void freezePlayer(SpleefPlayer player) { task.addFrozenPlayer(player); Player bukkitPlayer = player.getBukkitPlayer(); bukkitPlayer.setWalkSpeed(0F); PotionEffect noJumpEffect = new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, POTION_AMPLIFIER, true); bukkitPlayer.addPotionEffect(noJumpEffect, true); }
Example 5
Source File: FreezeHandler.java From StaffPlus with GNU General Public License v3.0 | 5 votes |
public void addFreeze(CommandSender sender, Player player, boolean shouldMessage) { UUID uuid = player.getUniqueId(); if(permission.has(player, options.permissionFreezeBypass) && shouldMessage) { message.send(sender, messages.bypassed, messages.prefixGeneral); return; } if(shouldMessage) { if(options.modeFreezePrompt) { new FreezeGui(player, options.modeFreezePromptTitle); player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Integer.MAX_VALUE, 128)); }else message.sendCollectedMessage(player, messages.freeze, messages.prefixGeneral); message.send(sender, messages.staffFroze.replace("%target%", player.getName()), messages.prefixGeneral); }else loggedOut.add(uuid); userManager.get(player.getUniqueId()).setFrozen(true); lastFrozenLocations.put(uuid, player.getLocation()); player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 128)); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 128)); options.modeFreezeSound.play(player); }
Example 6
Source File: Energizing.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void effect(Event e, ItemStack item, int level) { BlockBreakEvent event = (BlockBreakEvent) e; Player player = event.getPlayer(); player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Duration, Strength+level-1), false); }
Example 7
Source File: AttackWither.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onHit(EntityDamageByEntityEvent event) { EliteMobEntity eliteMobEntity = EventValidator.getEventEliteMob(this, event); if (eliteMobEntity == null) return; Player player = EntityFinder.findPlayer(event); if (PowerCooldown.isInCooldown(eliteMobEntity, cooldownList)) return; player.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1)); PowerCooldown.startCooldownTimer(eliteMobEntity, cooldownList, 10 * 20); }
Example 8
Source File: PlayersManager.java From UhcCore with GNU General Public License v3.0 | 5 votes |
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 9
Source File: AttackConfusing.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void attackConfusing(EntityDamageByEntityEvent event) { EliteMobEntity eliteMobEntity = EventValidator.getEventEliteMob(this, event); if (eliteMobEntity == null) return; Player player = EntityFinder.findPlayer(event); if (PowerCooldown.isInCooldown(eliteMobEntity, cooldowns)) return; player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 3)); PowerCooldown.startCooldownTimer(eliteMobEntity, cooldowns, 10 * 20); }
Example 10
Source File: TeleportationManager.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void updateProgress(UUID uuid, int speed, int progress, Location source, Location destination, boolean resistance) { Player p = Bukkit.getPlayer(uuid); if (isValid(p, source)) { if (progress > 99) { p.sendTitle(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.teleported")), ChatColors.color("&b100%"), 20, 60, 20); p.teleport(destination); if (resistance) { p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 600, 20)); SlimefunPlugin.getLocalization().sendMessage(p, "machines.TELEPORTER.invulnerability"); } destination.getWorld().spawnParticle(Particle.PORTAL, new Location(destination.getWorld(), destination.getX(), destination.getY() + 1, destination.getZ()), progress * 2, 0.2F, 0.8F, 0.2F); destination.getWorld().playSound(destination, Sound.BLOCK_BEACON_ACTIVATE, 1F, 1F); teleporterUsers.remove(uuid); } else { p.sendTitle(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.teleporting")), ChatColors.color("&b" + progress + "%"), 0, 60, 0); source.getWorld().spawnParticle(Particle.PORTAL, source, progress * 2, 0.2F, 0.8F, 0.2F); source.getWorld().playSound(source, Sound.BLOCK_BEACON_AMBIENT, 1F, 0.6F); Slimefun.runSync(() -> updateProgress(uuid, speed, progress + speed, source, destination, resistance), 10L); } } else { cancel(uuid, p); } }
Example 11
Source File: SuperHeroesListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private void addHeroesEffect(UhcPlayer uhcPlayer, int effect){ Player player; try { player = uhcPlayer.getPlayer(); }catch (UhcPlayerNotOnlineException ex){ // No effect for offline player return; } switch (effect){ case 0: player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999,0)); break; case 1: player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 999999,0)); break; case 2: player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 999999,1)); break; case 3: player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999,0)); break; case 4: player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 999999,3)); break; case 5: double maxHealth = 40; VersionUtils.getVersionUtils().setPlayerMaxHealth(player, maxHealth); player.setHealth(maxHealth); break; default: System.out.println("No effect for: " + effect); break; } }
Example 12
Source File: QAMain.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static void toggleNightvision(Player player, Gun g, boolean add) { if (add) { if (g.getZoomWhenIronSights() > 0) { currentlyScoping.add(player.getUniqueId()); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1200, g.getZoomWhenIronSights())); } if (g.hasnightVision()) { currentlyScoping.add(player.getUniqueId()); player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1200, 3)); } } else { if (currentlyScoping.contains(player.getUniqueId())) { if (player.hasPotionEffect(PotionEffectType.SLOW) && (g == null || g.getZoomWhenIronSights() > 0)) player.removePotionEffect(PotionEffectType.SLOW); boolean potionEff = false; try { potionEff = player.hasPotionEffect(PotionEffectType.NIGHT_VISION) && (g == null || g.hasnightVision()) && player.getPotionEffect(PotionEffectType.NIGHT_VISION).getAmplifier() == 3; } catch (Error | Exception e3452) { for (PotionEffect pe : player.getActivePotionEffects()) if (pe.getType() == PotionEffectType.NIGHT_VISION) potionEff = (g == null || g.hasnightVision()) && pe.getAmplifier() == 3; } if (potionEff) player.removePotionEffect(PotionEffectType.NIGHT_VISION); currentlyScoping.remove(player.getUniqueId()); } } }
Example 13
Source File: Assassin.java From AnnihilationPro with MIT License | 5 votes |
@SuppressWarnings("deprecation") @Override protected boolean performSpecialAction(Player player, AnniPlayer p) { p.setData("Arm",player.getInventory().getArmorContents().clone()); p.setData("Cur", true); player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,160,0)); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,160,0)); player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING,160,1)); player.getInventory().setArmorContents(null); player.updateInventory(); player.setVelocity(player.getLocation().getDirection().setY(1).multiply(1)); new EndLeap(player,p).runTaskLater(AnnihilationMain.getInstance(), 160); return true; }
Example 14
Source File: Cloaking.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void effect(Event e, ItemStack item, int level) { EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e; Player player = (Player) event.getEntity(); player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, duration * level, 0)); player.sendMessage(ChatColor.DARK_GRAY + "You have become invisible!"); generateCooldown(player, cooldown); }
Example 15
Source File: Berserk.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onHit(EntityDamageEvent event) { if (!(event.getEntity() instanceof Player)) { return; } Player player = (Player) event.getEntity(); if (!player.hasPermission("minetinker.modifiers.berserk.use")) { return; } ItemStack chest = player.getInventory().getChestplate(); if (!modManager.isArmorViable(chest)) { return; } int modifierLevel = modManager.getModLevel(chest, this); if (modifierLevel <= 0) { return; } double lifeAfterDamage = player.getHealth() - event.getFinalDamage(); AttributeInstance healthAttr = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); double maxHealth = 20; if (healthAttr != null) { maxHealth = healthAttr.getValue(); } if (player.getHealth() / maxHealth > trigger / 100.0 && lifeAfterDamage / maxHealth <= trigger / 100.0) { player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, boostTime, modifierLevel - 1)); ChatWriter.logModifier(player, event, this, chest, "Time(" + boostTime + ")", "Amplifier(" + (modifierLevel - 1) + ")"); } }
Example 16
Source File: Pyro.java From AnnihilationPro with MIT License | 5 votes |
@Override public void onPlayerSpawn(Player player) { player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0)); super.onPlayerSpawn(player); // KitUtils.giveTeamArmor(player); // player.getInventory().addItem(KitUtils.getStoneSword()); // player.getInventory().addItem(KitUtils.getWoodPick()); // player.getInventory().addItem(KitUtils.getWoodAxe()); // player.getInventory().addItem(KitUtils.getHealthPotion1()); // super.giveSpecialItem(player); // player.getInventory().addItem(KitUtils.getNavCompass()); }
Example 17
Source File: ClearPotionEffectsAction.java From UHC with MIT License | 4 votes |
@Override protected void revert(Player player) { for (final PotionEffect effect : effects) { player.addPotionEffect(effect); } }
Example 18
Source File: PotionAreaEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
private void applyPotion(String potionString, UUID uuid, String typeName, boolean isMember, String key) { for (String currentPotionString : potionString.split(",")) { String[] splitPotionString = currentPotionString.split("\\."); String potionTypeString = splitPotionString[0]; boolean invert = potionTypeString.startsWith("^"); if (invert) { potionTypeString = potionTypeString.substring(1); } if (invert == isMember) { return; } PotionEffectType potionType; int duration = 40; int amplifier = 1; int chance = 100; int cooldown = 0; try { potionType = PotionEffectType.getByName(potionTypeString); if (potionType == null) { Civs.logger.severe("Invalid potion type for " + typeName); return; } if (splitPotionString.length > 1) { duration = Integer.parseInt(splitPotionString[1]); } if (splitPotionString.length > 2) { amplifier = Integer.parseInt(splitPotionString[2]); } if (splitPotionString.length > 3) { chance = Integer.parseInt(splitPotionString[3]); chance = Math.max(Math.min(chance, 100), 0); } if (splitPotionString.length > 4) { cooldown = Integer.parseInt(splitPotionString[4]); cooldown = Math.max(cooldown, 0); } } catch (Exception e) { Civs.logger.severe("Invalid potion type for " + typeName); return; } if (Math.random() * 100 > chance) { return; } if (cooldown > 0) { cooldowns.put(key, System.currentTimeMillis() + (cooldown * 1000)); } PotionEffect potionEffect = new PotionEffect(potionType, duration * 20, amplifier); Player player = Bukkit.getPlayer(uuid); if (player == null) { return; } player.addPotionEffect(potionEffect); } }
Example 19
Source File: DeathStandsModule.java From UHC with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGH) public void on(PlayerDeathEvent event) { if (!isEnabled()) return; final Player player = event.getEntity(); // make the player invisible for the duration of their death animation player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, DEATH_ANIMATION_TIME, 1)); final Location location = player.getLocation(); // create an armour stand at the player final ArmorStand stand = player.getWorld().spawn(location.clone().add(0, .2D, 0), ArmorStand.class); stand.setBasePlate(false); stand.setArms(true); // give the armour stand the death message as a name stand.setCustomName(STAND_PREFIX + event.getDeathMessage()); stand.setCustomNameVisible(true); // face the same direction as the player stand.getLocation().setDirection(location.getDirection()); // set the armour stand helmet to be looking at the same yaw stand.setHeadPose(new EulerAngle(Math.toRadians(location.getPitch()), 0, 0)); // use the player's velocity as a base and apply it to the stand stand.setVelocity( player.getVelocity() .clone() .multiply(PLAYER_VELOCITY_MULTIPLIER) .add(new Vector(0D, PLAYER_VELOICY_Y_ADDITIONAL, 0D)) ); // start with player's existing items in each slot (if exists) Map<EquipmentSlot, ItemStack> toSet = getItems(player.getInventory()); // overide with any saved items in the metadata toSet.putAll(getSavedSlots(player)); // filter out the invalid items toSet = Maps.filterValues(toSet, Predicates.not(EMPTY_ITEM)); final List<ItemStack> drops = event.getDrops(); for (final Map.Entry<EquipmentSlot, ItemStack> entry : toSet.entrySet()) { final ItemStack stack = entry.getValue(); if (stack == null) continue; // remove the first matching stack in the drop list removeFirstEquals(drops, stack); // set the item on the armour stand in the correct slot switch (entry.getKey()) { case HAND: stand.setItemInHand(stack); break; case HEAD: stand.setHelmet(stack); break; case CHEST: stand.setChestplate(stack); break; case LEGS: stand.setLeggings(stack); break; case FEET: stand.setBoots(stack); break; default: } } }
Example 20
Source File: PotionEffectApplier.java From EliteMobs with GNU General Public License v3.0 | 2 votes |
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); } } } }