use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.
the class BeaconEntity method getEffect.
public PotionEffect getEffect(BeaconEffectPriority priority) {
PotionEffectType type = PotionEffectType.getById(priority == BeaconEffectPriority.PRIMARY ? primaryEffectId : secondaryEffectId);
if (type == null) {
return null;
}
int effectDuration = (9 + levels * 2) * 20;
int effectAmplifier = levels >= 4 && primaryEffectId == secondaryEffectId ? 1 : 0;
return new PotionEffect(type, effectDuration, effectAmplifier, true, true);
}
use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.
the class GlowPotionEffect method parsePotionEffectId.
/**
* Parses a PotionEffect id or name if possible.
*
* @param effectName The PotionEffectType name.
* @return The associated PotionEffectType, or null.
*/
public static PotionEffectType parsePotionEffectId(String effectName) {
try {
int effectId = Integer.parseInt(effectName);
PotionEffectType type = PotionEffectType.getById(effectId);
if (type == null) {
return null;
} else {
return type;
}
} catch (NumberFormatException exc) {
if (effectName.startsWith("minecraft:")) {
PotionEffectType type = GlowPotionEffect.getByVanillaId(effectName);
if (type == null) {
return null;
} else {
return type;
}
} else {
PotionEffectType type = PotionEffectType.getByName(effectName);
if (type == null) {
return null;
} else {
return type;
}
}
}
}
use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.
the class LivingEntityStore method load.
// these tags that apply to living entities only are documented as global:
// - short "Air"
// - string "CustomName"
// - bool "CustomNameVisible"
// todo: the following tags
// - float "AbsorptionAmount"
// - short "HurtTime"
// - int "HurtByTimestamp"
// - short "DeathTime"
// - bool "PersistenceRequired"
// on ActiveEffects, bool "ShowParticles"
@Override
public void load(T entity, CompoundTag compound) {
super.load(entity, compound);
compound.readShort("Air", entity::setRemainingAir);
compound.readString("CustomName", entity::setCustomName);
compound.readBoolean("CustomNameVisible", entity::setCustomNameVisible);
if (!compound.readFloat("HealF", entity::setHealth)) {
compound.readShort("Health", entity::setHealth);
}
compound.readShort("AttackTime", entity::setNoDamageTicks);
compound.readBoolean("FallFlying", entity::setFallFlying);
compound.iterateCompoundList("ActiveEffects", effect -> {
// should really always have every field, but be forgiving if possible
if (!effect.isByte("Id") || !effect.isInt("Duration")) {
return;
}
PotionEffectType type = PotionEffectType.getById(effect.getByte("Id"));
int duration = effect.getInt("Duration");
if (type == null || duration < 0) {
return;
}
final int amplifier = compound.tryGetInt("Amplifier").orElse(0);
boolean ambient = compound.getBoolean("Ambient", false);
// bool "ShowParticles"
entity.addPotionEffect(new PotionEffect(type, duration, amplifier, ambient), true);
});
EntityEquipment equip = entity.getEquipment();
if (equip != null) {
loadEquipment(entity, equip, compound);
}
compound.readBoolean("CanPickUpLoot", entity::setCanPickupItems);
AttributeManager am = entity.getAttributeManager();
compound.iterateCompoundList("Attributes", tag -> {
if (!tag.isString("Name") || !tag.isDouble("Base")) {
return;
}
List<AttributeModifier> modifiers = new ArrayList<>();
tag.iterateCompoundList("Modifiers", modifierTag -> {
if (modifierTag.isDouble("Amount") && modifierTag.isString("Name") && modifierTag.isInt("Operation") && modifierTag.isLong("UUIDLeast") && modifierTag.isLong("UUIDMost")) {
modifiers.add(new AttributeModifier(new UUID(modifierTag.getLong("UUIDLeast"), modifierTag.getLong("UUIDMost")), modifierTag.getString("Name"), modifierTag.getDouble("Amount"), AttributeModifier.Operation.values()[modifierTag.getInt("Operation")]));
}
});
AttributeManager.Key key = AttributeManager.Key.fromName(tag.getString("Name"));
am.setProperty(key, tag.getDouble("Base"), modifiers);
});
Optional<CompoundTag> maybeLeash = compound.tryGetCompound("Leash");
if (maybeLeash.isPresent()) {
CompoundTag leash = maybeLeash.get();
if (!leash.readUniqueId("UUIDMost", "UUIDLeast", entity::setLeashHolderUniqueId) && leash.isInt("X") && leash.isInt("Y") && leash.isInt("Z")) {
int x = leash.getInt("X");
int y = leash.getInt("Y");
int z = leash.getInt("Z");
LeashHitch leashHitch = GlowLeashHitch.getLeashHitchAt(new Location(entity.getWorld(), x, y, z).getBlock());
entity.setLeashHolder(leashHitch);
}
} else {
compound.readBoolean("Leashed", leashSet -> {
if (leashSet) {
// We know that there was something leashed, but not what entity it was
// This can happen, when for example Minecart got leashed
// We still have to make sure that we drop a Leash Item
entity.setLeashHolderUniqueId(UUID.randomUUID());
}
});
}
}
use of org.bukkit.potion.PotionEffectType in project TokenManager by RealizedMC.
the class ItemUtil method applyMeta.
private static void applyMeta(final ItemStack item, final String key, final String value) {
final ItemMeta meta = item.getItemMeta();
if (key.equalsIgnoreCase("name")) {
meta.setDisplayName(StringUtil.color(value.replace("_", " ")));
item.setItemMeta(meta);
return;
}
if (key.equalsIgnoreCase("lore")) {
meta.setLore(StringUtil.color(Lists.newArrayList(value.split("\\|")), s -> s.replace("_", " ")));
item.setItemMeta(meta);
return;
}
if (key.equalsIgnoreCase("unbreakable") && value.equalsIgnoreCase("true")) {
if (isPre1_12()) {
meta.spigot().setUnbreakable(true);
} else {
meta.setUnbreakable(true);
}
item.setItemMeta(meta);
return;
}
final Enchantment enchantment = ENCHANTMENTS.get(key);
if (enchantment != null) {
item.addUnsafeEnchantment(enchantment, Integer.parseInt(value));
return;
}
if (item.getType().name().contains("POTION")) {
final PotionEffectType effectType = EFFECTS.get(key);
if (effectType != null) {
String[] values = value.split(":");
PotionMeta potionMeta = (PotionMeta) meta;
potionMeta.addCustomEffect(new PotionEffect(effectType, Integer.parseInt(values[1]), Integer.parseInt(values[0])), true);
item.setItemMeta(potionMeta);
return;
}
}
if (item.getType() == Material.SKULL_ITEM && item.getDurability() == 3 && key.equalsIgnoreCase("player") || key.equalsIgnoreCase("owner")) {
final SkullMeta skullMeta = (SkullMeta) meta;
skullMeta.setOwner(value);
item.setItemMeta(skullMeta);
}
}
use of org.bukkit.potion.PotionEffectType in project Essentials by EssentialsX.
the class Commandpotion method run.
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final ItemStack stack = user.getItemInHand();
if (args.length == 0) {
final Set<String> potionslist = new TreeSet<>();
for (Map.Entry<String, PotionEffectType> entry : Potions.entrySet()) {
final String potionName = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
if (potionslist.contains(potionName) || (user.isAuthorized("essentials.potion." + potionName))) {
potionslist.add(entry.getKey());
}
}
throw new NotEnoughArgumentsException(tl("potions", StringUtil.joinList(potionslist.toArray())));
}
boolean holdingPotion = stack.getType() == Material.POTION;
if (!holdingPotion && ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_9_R1)) {
holdingPotion = stack.getType() == Material.SPLASH_POTION || stack.getType() == Material.LINGERING_POTION;
}
if (holdingPotion) {
PotionMeta pmeta = (PotionMeta) stack.getItemMeta();
if (args.length > 0) {
if (args[0].equalsIgnoreCase("clear")) {
pmeta.clearCustomEffects();
stack.setItemMeta(pmeta);
} else if (args[0].equalsIgnoreCase("apply") && user.isAuthorized("essentials.potion.apply")) {
for (PotionEffect effect : pmeta.getCustomEffects()) {
effect.apply(user.getBase());
}
} else if (args.length < 3) {
throw new NotEnoughArgumentsException();
} else {
final MetaItemStack mStack = new MetaItemStack(stack);
for (String arg : args) {
mStack.addPotionMeta(user.getSource(), true, arg, ess);
}
if (mStack.completePotion()) {
pmeta = (PotionMeta) mStack.getItemStack().getItemMeta();
stack.setItemMeta(pmeta);
} else {
user.sendMessage(tl("invalidPotion"));
throw new NotEnoughArgumentsException();
}
}
}
} else {
throw new Exception(tl("holdPotion"));
}
}
Aggregations