use of org.bukkit.potion.PotionEffectType in project Minigames by AddstarMC.
the class Minigames method setupLoadOuts.
private void setupLoadOuts() {
final MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
final Set<String> keys = globalLoadouts.getConfig().getKeys(false);
for (final String loadout : keys) {
this.minigameManager.addLoadout(loadout);
ConfigurationSection loadOutSection = globalLoadouts.getConfig().getConfigurationSection(loadout);
if (loadOutSection != null) {
final Set<String> items = loadOutSection.getKeys(false);
for (final String slot : items) {
if (COMPILE.matcher(slot).matches()) {
this.minigameManager.getLoadout(loadout).addItem(globalLoadouts.getConfig().getItemStack(loadout + '.' + slot), Integer.parseInt(slot));
}
}
}
if (globalLoadouts.getConfig().contains(loadout + ".potions")) {
ConfigurationSection potionLoadOutSection = globalLoadouts.getConfig().getConfigurationSection(loadout + ".potions");
if (potionLoadOutSection != null) {
final Set<String> pots = potionLoadOutSection.getKeys(false);
for (final String eff : pots) {
PotionEffectType type = PotionEffectType.getByName(eff);
if (type != null) {
final PotionEffect effect = new PotionEffect(type, globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".dur"), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".amp"));
this.minigameManager.getLoadout(loadout).addPotionEffect(effect);
}
}
}
}
if (globalLoadouts.getConfig().contains(loadout + ".usepermissions")) {
this.minigameManager.getLoadout(loadout).setUsePermissions(globalLoadouts.getConfig().getBoolean(loadout + ".usepermissions"));
}
}
}
use of org.bukkit.potion.PotionEffectType in project Minigames by AddstarMC.
the class MenuItemPotionAdd method checkValidEntry.
@Override
public void checkValidEntry(String entry) {
String[] split = entry.split(", ");
if (split.length == 3) {
String effect = split[0].toUpperCase();
if (PotionEffectType.getByName(effect) != null) {
PotionEffectType eff = PotionEffectType.getByName(effect);
if (split[1].matches("[0-9]+") && Integer.parseInt(split[1]) != 0) {
int level = Integer.parseInt(split[1]) - 1;
if ((split[2].matches("[0-9]+") && Integer.parseInt(split[2]) != 0) || split[2].equalsIgnoreCase("inf")) {
int dur = 0;
if (split[2].equalsIgnoreCase("inf"))
dur = 100000;
else
dur = Integer.parseInt(split[2]);
if (dur > 100000) {
dur = 100000;
}
dur *= 20;
List<String> des = new ArrayList<>();
des.add("Shift + Right Click to Delete");
PotionEffect peff = new PotionEffect(eff, dur, level);
for (int slot : getContainer().getSlotMap()) {
if (getContainer().getClicked(slot) instanceof MenuItemPotion) {
MenuItemPotion pot = (MenuItemPotion) getContainer().getClicked(slot);
if (pot.getEffect().getType() == peff.getType()) {
pot.onShiftRightClick();
break;
}
}
}
for (int i = 0; i < 36; i++) {
if (!getContainer().hasMenuItem(i)) {
getContainer().addItem(new MenuItemPotion(eff.getName().toLowerCase().replace("_", " "), des, Material.POTION, peff, loadout), i);
loadout.addPotionEffect(peff);
break;
}
}
} else
getContainer().getViewer().sendMessage(split[2] + " is not a valid duration! The time must be in seconds", MinigameMessageType.ERROR);
} else
getContainer().getViewer().sendMessage(split[1] + " is not a valid level number!", MinigameMessageType.ERROR);
} else
getContainer().getViewer().sendMessage(split[0] + " is not a valid potion name!", MinigameMessageType.ERROR);
getContainer().cancelReopenTimer();
getContainer().displayMenu(getContainer().getViewer());
return;
}
getContainer().cancelReopenTimer();
getContainer().displayMenu(getContainer().getViewer());
getContainer().getViewer().sendMessage("Invalid syntax entry! Make sure there is an comma and a space (\", \") between each item.", MinigameMessageType.ERROR);
}
use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.
the class GlowMetaPotion method fromNbt.
/**
* Reads a {@link PotionEffect} from an NBT compound tag.
*
* @param tag a potion effect NBT compound tag
* @return {@code tag} as a {@link PotionEffect}
*/
public static PotionEffect fromNbt(CompoundTag tag) {
PotionEffectType type = PotionEffectType.getById(tag.getByte("Id"));
int duration = tag.getInt("Duration");
int amplifier = tag.getByte("Amplifier");
boolean ambient = tag.getBoolean("Ambient", false);
boolean particles = tag.getBoolean("ShowParticles", true);
return new PotionEffect(type, duration, amplifier, ambient, particles);
}
use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.
the class GlowBeaconInventory method setActiveEffects.
public void setActiveEffects(int primaryId, int secondaryId) {
if (!ALLOWED_MATERIALS.contains(getItem().getType())) {
return;
}
PotionEffectType primaryType = PotionEffectType.getById(primaryId);
if (primaryType != null) {
((Beacon) getHolder()).setPrimaryEffect(primaryType);
}
PotionEffectType secondaryType = PotionEffectType.getById(secondaryId);
if (secondaryType != null) {
((Beacon) getHolder()).setSecondaryEffect(secondaryType);
}
getItem().add(-1);
}
use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method pulse.
// //////////////////////////////////////////////////////////////////////////
// Internals
@Override
public void pulse() {
super.pulse();
if (isDead()) {
deathTicks++;
if (deathTicks >= 20 && getClass() != GlowPlayer.class) {
remove();
}
}
// invulnerability
if (noDamageTicks > 0) {
--noDamageTicks;
}
Material mat = getEyeLocation().getBlock().getType();
// breathing
if (mat == Material.WATER) {
// todo: flowing_water?
if (canTakeDamage(DamageCause.DROWNING)) {
--remainingAir;
if (remainingAir <= -20) {
remainingAir = 0;
damage(1, DamageCause.DROWNING);
}
}
} else {
remainingAir = maximumAir;
}
if (isTouchingMaterial(Material.CACTUS)) {
damage(1, DamageCause.CONTACT);
}
if (location.getY() < -64) {
// no canTakeDamage call - pierces through game modes
damage(4, DamageCause.VOID);
}
if (isWithinSolidBlock()) {
damage(1, DamageCause.SUFFOCATION);
}
// fire and lava damage
if (getLocation().getBlock().getType() == Material.FIRE) {
damage(1, DamageCause.FIRE);
// not applying additional fire ticks after dying in fire
stoodInFire = !isDead();
} else if (getLocation().getBlock().getType() == Material.LAVA) {
damage(4, DamageCause.LAVA);
if (swamInLava) {
setFireTicks(getFireTicks() + 2);
} else {
setFireTicks(getFireTicks() + 300);
swamInLava = true;
}
} else if (isTouchingMaterial(Material.FIRE) || isTouchingMaterial(Material.LAVA)) {
damage(1, DamageCause.FIRE);
// increment the ticks stood adjacent to fire or lava
adjacentBurnTicks++;
if (adjacentBurnTicks > 40) {
stoodInFire = !isDead();
}
} else if (stoodInFire) {
setFireTicks(getFireTicks() + 160);
stoodInFire = false;
adjacentBurnTicks = 0;
} else {
swamInLava = false;
if (getLocation().getBlock().getType() == Material.WATER) {
setFireTicks(0);
}
}
// potion effects
List<PotionEffect> effects = new ArrayList<>(potionEffects.values());
for (PotionEffect effect : effects) {
// pulse effect
PotionEffectType type = effect.getType();
GlowPotionEffect glowType = GlowPotionEffect.getEffect(type);
if (glowType != null) {
glowType.pulse(this, effect);
}
if (effect.getDuration() > 0) {
// reduce duration on server-side. Don't need to be updated to client
potionEffects.put(type, effect.withDuration(effect.getDuration() - 1));
} else {
// remove
removePotionEffect(type);
}
}
if (potionEffectsChanged) {
updatePotionEffectsMetadata();
potionEffectsChanged = false;
}
if (getFireTicks() > 0 && getFireTicks() % 20 == 0) {
damage(1, DamageCause.FIRE_TICK);
}
GlowBlock under = (GlowBlock) getLocation().getBlock().getRelative(BlockFace.DOWN);
BlockType type = ItemTable.instance().getBlock(under.getType());
if (type != null) {
type.onEntityStep(under, this);
}
nextAmbientTime--;
if (!isDead() && getAmbientSound() != null && nextAmbientTime == 0 && !isSilent()) {
double v = ThreadLocalRandom.current().nextDouble();
if (v <= 0.2) {
world.playSound(getLocation(), getAmbientSound(), getSoundVolume(), getSoundPitch());
}
}
if (nextAmbientTime == 0) {
nextAmbientTime = getAmbientDelay();
}
}
Aggregations