org.bukkit.potion.PotionEffectType Java Examples

The following examples show how to use org.bukkit.potion.PotionEffectType. 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: PotionEffectSerializerTest.java    From PerWorldInventory with GNU General Public License v3.0 7 votes vote down vote up
@Test
public void serializePotionEffectWithParticlesAndColor() {
    // given
    ArrayList<PotionEffect> effects = new ArrayList<>();
    PotionEffect effect = new PotionEffect(PotionEffectType.CONFUSION, 30, 1, true, true, Color.AQUA);
    effects.add(effect);

    // when
    JsonArray serialized = PotionEffectSerializer.serialize(effects);

    // then
    JsonObject json = serialized.get(0).getAsJsonObject();
    assertTrue(json.get("type").getAsString().equals("CONFUSION"));
    assertTrue(json.get("amp").getAsInt() == 1);
    assertTrue(json.get("duration").getAsInt() == 30);
    assertTrue(json.get("ambient").getAsBoolean());
    assertTrue(json.get("particles").getAsBoolean());
    assertTrue(Color.fromRGB(json.get("color").getAsInt()) == Color.AQUA);
}
 
Example #2
Source File: SentinelUtilities.java    From Sentinel with MIT License 7 votes vote down vote up
/**
 * Returns whether an entity is invisible (when invisible targets are ignorable).
 */
public static boolean isInvisible(LivingEntity entity) {
    if (!SentinelPlugin.instance.ignoreInvisible
            || !entity.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
        return false;
    }
    EntityEquipment eq = entity.getEquipment();
    if (eq == null) {
        return true;
    }
    if (SentinelVersionCompat.v1_9) {
        if (!isAir(eq.getItemInMainHand()) || !isAir(eq.getItemInOffHand())) {
            return false;
        }
    }
    else {
        if (!isAir(eq.getItemInHand())) {
            return false;
        }
    }
    return isAir(eq.getBoots()) && isAir(eq.getLeggings()) && isAir(eq.getChestplate()) && isAir(eq.getHelmet());
}
 
Example #3
Source File: MagicSugar.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        // Check if it is being placed into an ancient altar.
        if (e.getClickedBlock().isPresent()) {
            Material block = e.getClickedBlock().get().getType();

            if (block == Material.DISPENSER || block == Material.ENCHANTING_TABLE) {
                return;
            }
        }

        Player p = e.getPlayer();
        if (p.getGameMode() != GameMode.CREATIVE) {
            ItemUtils.consumeItem(e.getItem(), false);
        }

        p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
        p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 600, 3));
    };
}
 
Example #4
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public boolean removeCustomEffect(PotionEffectType type) {
    Validate.notNull(type, "Potion effect type must not be null");

    if (!hasCustomEffects()) {
        return false;
    }

    boolean changed = false;
    Iterator<PotionEffect> iterator = customEffects.iterator();
    while (iterator.hasNext()) {
        PotionEffect effect = iterator.next();
        if (type.equals(effect.getType())) {
            iterator.remove();
            changed = true;
        }
    }
    if (customEffects.isEmpty()) {
        customEffects = null;
    }
    return changed;
}
 
Example #5
Source File: GhostSquadronMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private void reveal(Player player, int ticks) {
    RevealEntry entry = this.revealMap.get(player);
    if(entry == null) entry = new RevealEntry();

    entry.revealTicks = ticks;

    for(PotionEffect e : player.getActivePotionEffects()) {
        if(e.getType().equals(PotionEffectType.INVISIBILITY)) {
            entry.potionTicks = e.getDuration();
        }
    }

    player.removePotionEffect(PotionEffectType.INVISIBILITY);

    this.revealMap.put(player, entry);
}
 
Example #6
Source File: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onHit(ProjectileHitEvent event) {
    Projectile projectile = event.getEntity();

    if (projectile instanceof Arrow) {
        projectile.remove();
    } else if (projectile instanceof Snowball && event.getEntity() instanceof Player) {
        ((Player) event.getEntity()).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20 * 2, 1));
    } else if (projectile instanceof Egg && projectile.getShooter() instanceof Player) {
        projectile.getWorld().createExplosion(projectile.getLocation(), 0.0F);

        for (Entity entity : projectile.getNearbyEntities(5, 5, 5)) {
            if (entity instanceof Player) {
                Player player = (Player) entity;
                if (plugin.getGameArena().isZombie(player)) {
                    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 5, 1));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 5, 1));
                }
            }
        }
    }
}
 
Example #7
Source File: DelEffectEvent.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
public DelEffectEvent(Instruction instruction) throws InstructionParseException {
    super(instruction, true);
    String next = instruction.next();

    if (next.equalsIgnoreCase("any")) {
        any = true;
        effects = Collections.emptyList();
    } else {
        any = false;
        effects = instruction.getList(next, (type -> {
            PotionEffectType effect = PotionEffectType.getByName(type.toUpperCase());
            if (effect == null) throw new InstructionParseException("Effect type '" + type + "' does not exist");
            else return effect;
        }));
    }
}
 
Example #8
Source File: MobSelector.java    From CloudNet with Apache License 2.0 6 votes vote down vote up
@Deprecated
public void unstableEntity(Entity entity) {
    try {
        Class<?> nbt = ReflectionUtil.reflectNMSClazz(".NBTTagCompound");
        Class<?> entityClazz = ReflectionUtil.reflectNMSClazz(".Entity");
        Object object = nbt.newInstance();

        Object nmsEntity = entity.getClass().getMethod("getHandle", new Class[] {}).invoke(entity);
        try {
            entityClazz.getMethod("e", nbt).invoke(nmsEntity, object);
        } catch (Exception ex) {
            entityClazz.getMethod("save", nbt).invoke(nmsEntity, object);
        }

        object.getClass().getMethod("setInt", String.class, int.class).invoke(object, "NoAI", 1);
        object.getClass().getMethod("setInt", String.class, int.class).invoke(object, "Silent", 1);
        entityClazz.getMethod("f", nbt).invoke(nmsEntity, object);
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        e.printStackTrace();
        System.out.println("[CLOUD] Disabling NoAI and Silent support for " + entity.getEntityId());
        ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 100));
    }
}
 
Example #9
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 #10
Source File: FlagInvisibleSpectate.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Subscribe
public void onSpectateGame(FlagSpectate.SpectateEnteredEvent event) {
	SpleefPlayer player = event.getPlayer();
	Player bukkitPlayer = player.getBukkitPlayer();
	
	team.addPlayer(bukkitPlayer);
	
	PotionEffect effect = new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0, true);
	bukkitPlayer.addPotionEffect(effect, true);
	
	for (SpleefPlayer ingamePlayer : game.getPlayers()) {
		if (!ingamePlayer.getBukkitPlayer().canSee(bukkitPlayer)) {
			continue;
		}
		
		ingamePlayer.getBukkitPlayer().hidePlayer(bukkitPlayer);
	}
	
	bukkitPlayer.setScoreboard(scoreboard);
}
 
Example #11
Source File: PotionEffectUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get potion string representation.
 * @param effect
 * @param extended
 * @param strong
 * @return
 */
public static String getPotionName(@Nullable PotionEffectType effect, boolean extended, boolean strong) {
	if (effect == null) return "bottle of water"; 
	
	String s = "";
	if (extended) s += "extended";
	else if (strong) s += "strong";
	s += " potion of ";
	s += toString(effect);
	
	return s;
}
 
Example #12
Source File: FlagFreeze.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
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 #13
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public boolean setMainEffect(PotionEffectType type) {
    Validate.notNull(type, "Potion effect type must not be null");
    int index = indexOfEffect(type);
    if (index == -1 || index == 0) {
        return false;
    }

    PotionEffect old = customEffects.get(0);
    customEffects.set(0, customEffects.get(index));
    customEffects.set(index, old);
    return true;
}
 
Example #14
Source File: TitleRespawn.java    From CardinalPGM with MIT License 5 votes vote down vote up
private void killPlayer(final Player player, Player killer, EntityDamageEvent.DamageCause cause) {
    if (deadPlayers.containsKey(player.getUniqueId())) return;
    this.deadPlayers.put(player.getUniqueId(), System.currentTimeMillis());

    CardinalDeathEvent cardinalDeathEvent = new CardinalDeathEvent(player, killer, cause);
    Bukkit.getServer().getPluginManager().callEvent(cardinalDeathEvent);

    dropInventory(player, true);

    PlayerDeathEvent deathEvent = new PlayerDeathEvent(player, new ArrayList<ItemStack>(), player.getExpToLevel(), 0, 0, 0, null);
    deathEvent.setDeathMessage(null);
    Bukkit.getServer().getPluginManager().callEvent(deathEvent);

    if (!isDeadUUID(player.getUniqueId())) return;

    Players.setObserver(player);

    PlayerNameUpdateEvent nameUpdateEvent = new PlayerNameUpdateEvent(player);
    Bukkit.getServer().getPluginManager().callEvent(nameUpdateEvent);

    sendTitle(player);

    player.setGameMode(GameMode.CREATIVE);

    setBlood(player, true);
    playDeathAnimation(player);

    if (!this.spectate) sendArmorStandPacket(player);

    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 0, true, false), false);
    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, this.blackout ? Integer.MAX_VALUE : 20, 0, true, false), false);

    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Cardinal.getInstance(), new Runnable() {
        public void run() {
            GameHandler.getGameHandler().getMatch().getModules().getModule(Visibility.class).showOrHide(player);
        }
    }, 15L);
    if (this.auto) hasLeftClicked.add(player.getUniqueId());
}
 
Example #15
Source File: CraftAreaEffectCloud.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean hasCustomEffect(PotionEffectType type) {
    for (net.minecraft.potion.PotionEffect effect : getHandle().effects) {
        if (CraftPotionUtil.equals(effect.getPotion(), type)) {
            return true;
        }
    }
    return false;
}
 
Example #16
Source File: PotionEffectUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLanguageChange() {
	types.clear();
	for (final PotionEffectType t : PotionEffectType.values()) {
		if (t == null)
			continue;
		final String[] ls = Language.getList("potions." + t.getName());
		names[t.getId()] = ls[0];
		for (final String l : ls) {
			types.put(l.toLowerCase(), t);
		}
	}
}
 
Example #17
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is PotionSplashEvent");

    ProjectileSource thrower = event.getPotion().getShooter();
    for (PotionEffect e : event.getPotion().getEffects()) {
        PotionEffectType t = e.getType();
        if (!t.equals(PotionEffectType.BLINDNESS) && !t.equals(PotionEffectType.CONFUSION) && !t.equals(PotionEffectType.HARM) && !t.equals(PotionEffectType.HUNGER) && !t.equals(PotionEffectType.POISON) && !t.equals(PotionEffectType.SLOW) && !t.equals(PotionEffectType.SLOW_DIGGING) && !t.equals(PotionEffectType.WEAKNESS) && !t.equals(PotionEffectType.WITHER)) {
            return;
        }
    }
    Player shooter;
    if (thrower instanceof Player) {
        shooter = (Player) thrower;
    } else {
        return;
    }
    for (Entity e2 : event.getAffectedEntities()) {
        Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (event.getEntity() instanceof Player) {
            if (r != null && r.flagExists("pvp") && !r.canPVP((Player) event.getEntity(), shooter)) {
                event.setCancelled(true);
                return;
            }
        } else {
            if (r != null && !r.canInteractPassives(shooter)) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #18
Source File: MoonWalk.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void applyPowers(Entity entity) {
    new BukkitRunnable() {
        @Override
        public void run() {
            ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 100000, 3));
        }
    }.runTaskLater(MetadataHandler.PLUGIN, 1);

}
 
Example #19
Source File: Swimsuit.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(player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) {
		if((player.getEquipment().getHelmet() != null && player.getEquipment().getHelmet().hasItemMeta() && player.getEquipment().getHelmet().getItemMeta().hasDisplayName() && player.getEquipment().getHelmet().getItemMeta().getDisplayName().equals(parts[0])) || (player.getEquipment().getChestplate() != null && player.getEquipment().getChestplate().hasItemMeta() && player.getEquipment().getChestplate().getItemMeta().hasDisplayName() && player.getEquipment().getChestplate().getItemMeta().getDisplayName().equals(parts[1])) || (player.getEquipment().getLeggings() != null && player.getEquipment().getLeggings().hasItemMeta() && player.getEquipment().getLeggings().getItemMeta().hasDisplayName() && player.getEquipment().getLeggings().getItemMeta().getDisplayName().equals(parts[2])) || (player.getEquipment().getBoots() != null && player.getEquipment().getBoots().hasItemMeta() && player.getEquipment().getBoots().getItemMeta().hasDisplayName() && player.getEquipment().getBoots().getItemMeta().getDisplayName().equals(parts[3]))) {

			addLock(player);

			new BukkitRunnable() {

				@Override
				public void run() {

					if(player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) {
						if((player.getEquipment().getHelmet() != null && player.getEquipment().getHelmet().hasItemMeta() && player.getEquipment().getHelmet().getItemMeta().hasDisplayName() && player.getEquipment().getHelmet().getItemMeta().getDisplayName().equals(parts[0])) || (player.getEquipment().getChestplate() != null && player.getEquipment().getChestplate().hasItemMeta() && player.getEquipment().getChestplate().getItemMeta().hasDisplayName() && player.getEquipment().getChestplate().getItemMeta().getDisplayName().equals(parts[1])) || (player.getEquipment().getLeggings() != null && player.getEquipment().getLeggings().hasItemMeta() && player.getEquipment().getLeggings().getItemMeta().hasDisplayName() && player.getEquipment().getLeggings().getItemMeta().getDisplayName().equals(parts[2])) || (player.getEquipment().getBoots() != null && player.getEquipment().getBoots().hasItemMeta() && player.getEquipment().getBoots().getItemMeta().hasDisplayName() && player.getEquipment().getBoots().getItemMeta().getDisplayName().equals(parts[3]))) {
							player.setRemainingAir(player.getMaximumAir());
							player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 120, SpeedBoostLevel), true);
							player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, DamageBoostLevel), true);

						} else {
							removeLock(player);
						}

					} else {
						removeLock(player);
					}
				}
			}.runTaskTimer(main, 0l, 80l);
		}

	}
	return true;
}
 
Example #20
Source File: ShadowDive.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onSneak(PlayerToggleSneakEvent event) {
	Player player = event.getPlayer();
	if (!player.hasPermission("minetinker.modifiers.shadowdive.use")) return;

	ItemStack boots = player.getInventory().getBoots();
	if (!modManager.isArmorViable(boots)) return;
	if (!modManager.hasMod(boots, this)) return;

	if (event.isSneaking() && !player.isGliding()) { //enable
		Location loc = player.getLocation();
		byte lightlevel = player.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()).getLightLevel();
		boolean combatTagged = PlayerInfo.isCombatTagged(player);
		ChatWriter.logModifier(player, event, this, boots,
				String.format("LightLevel(%d/%d)", lightlevel, this.requiredLightLevel),
				String.format("InCombat(%b)", combatTagged));
		if (lightlevel > this.requiredLightLevel || player.hasPotionEffect(PotionEffectType.GLOWING)) {
			ChatWriter.sendActionBar(player, ChatColor.RED + this.getName() + ": "
					+ LanguageManager.getString("Modifier.Shadow-Dive.LightToHigh", player));
			return;
		}

		if (combatTagged) {
			ChatWriter.sendActionBar(player, ChatColor.RED + this.getName() + ": "
					+ LanguageManager.getString("Modifier.Shadow-Dive.InCombat", player));
			return;
		}

		hidePlayer(player);

	} else { //disable
		if (!activePlayers.contains(player)) return;
		showPlayer(player);
	}
}
 
Example #21
Source File: CivPotionEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public CivPotionEffect(Spell spell, String key, Object target, Entity origin, int level, String value) {
    super(spell, key, target, origin, level, value);
    this.type = PotionEffectType.getByName(value);
    this.ticks = 40;
    this.level = 1;
    this.target = "self";

    this.potion = new PotionEffect(type, ticks, this.level);
}
 
Example #22
Source File: BukkitUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String potionEffectTypeName(final PotionEffectType type) {
    String name = POTION_EFFECT_MAP.get(type);
    if (name != null) {
        return name;
    } else {
        return "Unknown";
    }
}
 
Example #23
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String getTranslationKey(PotionEffectType effect) {
    if(effect instanceof CraftPotionEffectType) {
        return ((CraftPotionEffectType) effect).getHandle().a();
    } else if(effect instanceof PotionEffectTypeWrapper) {
        return getTranslationKey(((PotionEffectTypeWrapper) effect).getType());
    } else {
        return "potion.empty";
    }
}
 
Example #24
Source File: MojangGameLanguageImpl.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public @NotNull String getPotion(@NotNull PotionEffectType potionEffectType) {
    if (lang == null) {
        return super.getPotion(potionEffectType);
    }
    try {
        return lang.get("effect.minecraft." + potionEffectType.getName().toLowerCase()).getAsString();
    } catch (NullPointerException e) {
        return super.getPotion(potionEffectType);
    }
}
 
Example #25
Source File: PotionKit.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void applyEffect(MatchPlayer player, boolean force) {
    if(effect.getType().equals(PotionEffectType.HEALTH_BOOST)) {
        // Convert negative HB to max-health kit
        if(effect.getAmplifier() == -1 || effect.getDuration() == 0) {
            // Level 0 or zero-duration HB resets max health
            player.getBukkit().setMaxHealth(20);
            return;
        } else if(effect.getAmplifier() < -1 && effect.getDuration() == Integer.MAX_VALUE) {
            // Level < 0 HB with inf duration converts to a MH kit
            player.getBukkit().setMaxHealth(20 + (effect.getAmplifier() + 1) * 4);
            return;
        }
    }
    player.getBukkit().addPotionEffect(effect, force);
}
 
Example #26
Source File: Rag.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();

        // Player is neither burning nor injured
        if (p.getFireTicks() <= 0 && p.getHealth() >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
            return;
        }

        if (p.getGameMode() != GameMode.CREATIVE) {
            ItemUtils.consumeItem(e.getItem(), false);
        }

        p.getWorld().playEffect(p.getLocation(), Effect.STEP_SOUND, Material.WHITE_WOOL);
        p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 0));
        p.setFireTicks(0);

        e.cancel();
    };
}
 
Example #27
Source File: Paralyze.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	if(e instanceof EntityDamageByEntityEvent) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	LivingEntity target = (LivingEntity) event.getEntity();
	target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, duration + (level-1)*20, strength + level-1), true);
	target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration + (level-1)*20, 1), true);
	target.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, duration + (level-1)*20, strength + level-1), true);
	}
}
 
Example #28
Source File: Items.java    From TabooLib with MIT License 5 votes vote down vote up
public static PotionEffectType asPotionEffectType(String potion) {
    try {
        PotionEffectType type = PotionEffectType.getByName(potion);
        return type != null ? type : PotionEffectType.getById(NumberConversions.toInt(potion));
    } catch (Throwable e) {
        return null;
    }
}
 
Example #29
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 #30
Source File: MsgUtil.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
public static void loadPotioni18n() {
    plugin.getLogger().info("Starting loading potions translation...");
    File potioni18nFile = new File(plugin.getDataFolder(), "potioni18n.yml");
    if (!potioni18nFile.exists()) {
        plugin.getLogger().info("Creating potioni18n.yml");
        plugin.saveResource("potioni18n.yml", false);
    }
    // Store it
    potioni18n = YamlConfiguration.loadConfiguration(potioni18nFile);
    potioni18n.options().copyDefaults(false);
    YamlConfiguration potioni18nYAML =
            YamlConfiguration.loadConfiguration(
                    new InputStreamReader(Objects.requireNonNull(plugin.getResource("potioni18n.yml"))));
    potioni18n.setDefaults(potioni18nYAML);
    Util.parseColours(potioni18n);
    for (PotionEffectType potion : PotionEffectType.values()) {
        String potionI18n = potioni18n.getString("potioni18n." + potion.getName().trim());
        if (potionI18n != null && !potionI18n.isEmpty()) {
            continue;
        }
        String potionName = gameLanguage.getPotion(potion);
        plugin.getLogger().info("Found new potion [" + potionName + "] , adding it to the config...");
        potioni18n.set("potioni18n." + potion.getName(), potionName);
    }
    try {
        potioni18n.save(potioni18nFile);
    } catch (IOException e) {
        e.printStackTrace();
        plugin
                .getLogger()
                .log(
                        Level.WARNING,
                        "Could not load/save transaction potionname from potioni18n.yml. Skipping.");
    }
    plugin.getLogger().info("Complete to load potions effect translation.");
}