org.bukkit.attribute.Attribute Java Examples
The following examples show how to use
org.bukkit.attribute.Attribute.
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: Splint.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@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().playSound(p.getLocation(), Sound.ENTITY_SKELETON_HURT, 1, 1); p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 0)); e.cancel(); }; }
Example #2
Source File: PWIPlayerManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
private Player mockPlayer(String name, GameMode gameMode) { Player mock = mock(Player.class); PlayerInventory inv = mock(PlayerInventory.class); inv.setContents(new ItemStack[39]); inv.setArmorContents(new ItemStack[4]); Inventory enderChest = mock(Inventory.class); enderChest.setContents(new ItemStack[27]); given(mock.getInventory()).willReturn(inv); given(mock.getEnderChest()).willReturn(enderChest); given(mock.getName()).willReturn(name); given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID); given(mock.getGameMode()).willReturn(gameMode); AttributeInstance attribute = mock(AttributeInstance.class); given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute); given(attribute.getBaseValue()).willReturn(20.0); return mock; }
Example #3
Source File: DInstancePlayer.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
/** * Clear the player's inventory, potion effects etc. * <p> * Does NOT handle flight. */ public void clearPlayerData() { player.getInventory().clear(); player.getInventory().setArmorContents(null); player.setExp(0f); player.setLevel(0); double maxHealth; if (is1_9) { maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); } else { maxHealth = player.getMaxHealth(); } player.setHealth(maxHealth); player.setFoodLevel(20); player.setExp(0f); player.setLevel(0); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } if (is1_9) { player.setCollidable(true); player.setInvulnerable(false); } }
Example #4
Source File: Modifier.java From MineTinker with GNU General Public License v3.0 | 6 votes |
/** * what should be done to the Tool if the Modifier gets removed * * @param tool the Tool */ public void removeMod(ItemStack tool) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { for (Enchantment enchantment : getAppliedEnchantments()) { meta.removeEnchant(enchantment); } for (Attribute attribute : getAppliedAttributes()) { meta.removeAttributeModifier(attribute); } tool.setItemMeta(meta); } }
Example #5
Source File: KillerProjectiles.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onDamagePlayer(ProjectileHitEvent event) { if (event.getHitEntity() instanceof Player) { Player player = (Player) event.getHitEntity(); Projectile projectile = event.getEntity(); Region r = RedProtect.get().rm.getTopRegion(projectile.getLocation()); double damage; if (getConfig().getString("projectile-damage").endsWith("%")) { damage = (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue() / 100) * Double.valueOf(getConfig().getString("projectile-damage", "100%").replace("%", "")); } else { damage = getConfig().getInt("projectile-damage"); } if (r != null && r.getFlagBool("killer-projectiles") && getConfig().getStringList("allowed-types").contains(projectile.getType().name())) { player.setHealth(damage); } } }
Example #6
Source File: SuperMobConstructor.java From EliteMobs with GNU General Public License v3.0 | 6 votes |
public static LivingEntity constructSuperMob(LivingEntity livingEntity) { if (!SuperMobProperties.isValidSuperMobType(livingEntity)) { Bukkit.getLogger().warning("[EliteMobs] Attempted to construct an invalid supermob. Report this to the dev!"); return null; } String name = ChatColorConverter.convert(SuperMobProperties.getDataInstance(livingEntity).getName()); double newMaxHealth = SuperMobProperties.getDataInstance(livingEntity).getDefaultMaxHealth() * ConfigValues.defaultConfig.getInt(DefaultConfig.SUPERMOB_STACK_AMOUNT); livingEntity.setCustomName(name); livingEntity.setCustomNameVisible(true); livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(newMaxHealth); livingEntity.setHealth(newMaxHealth); EntityTracker.registerSuperMob(livingEntity); return livingEntity; }
Example #7
Source File: Bandage.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@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, 1)); p.setFireTicks(0); e.cancel(); }; }
Example #8
Source File: PWIPlayer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
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 #9
Source File: CraftAttributeMap.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public AttributeInstance getAttribute(Attribute attribute) { Preconditions.checkArgument(attribute != null, "attribute"); net.minecraft.entity.ai.attributes.IAttributeInstance nms = handle.getAttributeInstanceByName(toMinecraft(attribute.name())); return (nms == null) ? null : new CraftAttributeInstance(nms, attribute); }
Example #10
Source File: Speedy.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta == null) { return false; } //To check if armor modifiers are on the armor Collection<AttributeModifier> attributeModifiers = meta.getAttributeModifiers(Attribute.GENERIC_ARMOR); if (attributeModifiers == null || attributeModifiers.isEmpty()) { modManager.addArmorAttributes(tool); meta = tool.getItemMeta(); } Collection<AttributeModifier> speedModifiers = meta.getAttributeModifiers(Attribute.GENERIC_MOVEMENT_SPEED); double speedOnItem = 0.0D; if (!(speedModifiers == null || speedModifiers.isEmpty())) { HashSet<String> names = new HashSet<>(); for (AttributeModifier am : speedModifiers) { if (names.add(am.getName())) speedOnItem += am.getAmount(); } } meta.removeAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED); meta.addAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED, new AttributeModifier(UUID.randomUUID(), (MineTinker.is16compatible) ? "generic.movement_speed" : "generic.movementSpeed", speedOnItem + this.speedPerLevel, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.LEGS)); meta.addAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED, new AttributeModifier(UUID.randomUUID(), (MineTinker.is16compatible) ? "generic.movement_speed" : "generic.movementSpeed", speedOnItem + this.speedPerLevel, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.FEET)); tool.setItemMeta(meta); return true; }
Example #11
Source File: DieObjective.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onLastDamage(EntityDamageEvent event) { if (!cancel) { return; } if (event.getEntity() instanceof Player) { final Player player = (Player) event.getEntity(); final String playerID = PlayerConverter.getID(player); if (containsPlayer(playerID) && player.getHealth() - event.getFinalDamage() <= 0 && checkConditions(playerID)) { event.setCancelled(true); player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); player.setFoodLevel(20); player.setExhaustion(4); player.setSaturation(20); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } if (location != null) { try { player.teleport(location.getLocation(playerID)); } catch (QuestRuntimeException e) { LogUtils.getLogger().log(Level.SEVERE, "Couldn't execute onLastDamage in DieObjective"); LogUtils.logThrowable(e); } } new BukkitRunnable() { @Override public void run() { player.setFireTicks(0); } }.runTaskLater(BetonQuest.getInstance(), 1); completeObjective(playerID); } } }
Example #12
Source File: AttributeParser.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override protected Attribute parseInternal(Node node, String text) throws FormatException, InvalidXMLException { Attribute attribute = Attribute.byName(text); if(attribute != null) return attribute; attribute = Attribute.byName("generic." + text); if(attribute != null) return attribute; throw new InvalidXMLException("Unknown attribute '" + text + "'", node); }
Example #13
Source File: ParserManifest.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void configure() { NumberFactory.numberTypes().forEach(type -> bindNumber((Class) type)); bindPrimitiveParser(Boolean.class).to(BooleanParser.class); bindPrimitiveParser(String.class).to(StringParser.class); bindPrimitiveParser(Duration.class).to(DurationParser.class); bindPrimitiveParser(ImVector.class).to(new TypeLiteral<VectorParser<Double>>(){}); bindPrimitiveParser(Vector.class).to((TypeLiteral) new TypeLiteral<PrimitiveParser<ImVector>>(){}); bindPrimitiveParser(Team.OptionStatus.class).to(TeamRelationParser.class); bindPrimitiveParser(MessageTemplate.class).to(MessageTemplateParser.class); bindPrimitiveParser(Material.class).to(MaterialParser.class); bindPrimitiveParser(MaterialData.class).to(MaterialDataParser.class); bindPrimitiveParser(Attribute.class).to(AttributeParser.class); bind(PercentageParser.class); bind(PercentagePropertyFactory.class); install(new EnumPropertyManifest<ChatColor>(){}); install(new EnumPropertyManifest<EntityType>(){}); install(new EnumPropertyManifest<DyeColor>(){}); // etc... install(new PropertyManifest<>(Boolean.class)); install(new PropertyManifest<>(String.class)); install(new PropertyManifest<>(Duration.class, DurationProperty.class)); install(new PropertyManifest<>(ImVector.class)); install(new PropertyManifest<>(Vector.class)); install(new PropertyManifest<>(MessageTemplate.class, MessageTemplateProperty.class)); }
Example #14
Source File: ModManager.java From MineTinker with GNU General Public License v3.0 | 5 votes |
/** * Gets the first found modifier that applies the supplied attribute. * * @param attribute * @return the Modifier or null */ @Nullable public Modifier getModifierFromAttribute(@NotNull Attribute attribute) { for (Modifier modifier : getAllMods()) { if (modifier.getAppliedAttributes().contains(attribute)) { return modifier; } } return null; }
Example #15
Source File: SuperMobScanner.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
private static void checkLostSuperMob(LivingEntity livingEntity) { new BukkitRunnable() { @Override public void run() { if (livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() != SuperMobProperties.getSuperMobMaxHealth(livingEntity)) return; if (!EntityTracker.isSuperMob(livingEntity)) EntityTracker.registerSuperMob(livingEntity); } }.runTaskAsynchronously(MetadataHandler.PLUGIN); }
Example #16
Source File: AttributeFilter.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean matches(IPlayerQuery query) { return query.onlinePlayer() .filter(player -> range.contains(player.getBukkit() .getAttribute(Attribute.GENERIC_LUCK) .getValue())) .isPresent(); }
Example #17
Source File: DGlobalPlayer.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
public void heal() { if (is1_9) { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); } else { player.setHealth(player.getMaxHealth()); } player.setFoodLevel(20); player.setFireTicks(0); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } }
Example #18
Source File: VersionUtils_1_13.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public JsonObject getItemAttributes(ItemMeta meta){ if (!meta.hasAttributeModifiers()){ return null; } JsonObject attributesJson = new JsonObject(); Multimap<Attribute, AttributeModifier> attributeModifiers = meta.getAttributeModifiers(); for (Attribute attribute : attributeModifiers.keySet()){ JsonArray modifiersJson = new JsonArray(); Collection<AttributeModifier> modifiers = attributeModifiers.get(attribute); for (AttributeModifier modifier : modifiers){ JsonObject modifierObject = new JsonObject(); modifierObject.addProperty("name", modifier.getName()); modifierObject.addProperty("amount", modifier.getAmount()); modifierObject.addProperty("operation", modifier.getOperation().name()); if (modifier.getSlot() != null){ modifierObject.addProperty("slot", modifier.getSlot().name()); } modifiersJson.add(modifierObject); } attributesJson.add(attribute.name(), modifiersJson); } return attributesJson; }
Example #19
Source File: VersionUtils_1_13.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@Override public ItemMeta applyItemAttributes(ItemMeta meta, JsonObject attributes){ Set<Map.Entry<String, JsonElement>> entries = attributes.entrySet(); for (Map.Entry<String, JsonElement> attributeEntry : entries){ Attribute attribute = Attribute.valueOf(attributeEntry.getKey()); for (JsonElement jsonElement : attributeEntry.getValue().getAsJsonArray()) { JsonObject modifier = jsonElement.getAsJsonObject(); String name = modifier.get("name").getAsString(); double amount = modifier.get("amount").getAsDouble(); String operation = modifier.get("operation").getAsString(); EquipmentSlot slot = null; if (modifier.has("slot")){ slot = EquipmentSlot.valueOf(modifier.get("slot").getAsString()); } meta.addAttributeModifier(attribute, new AttributeModifier( UUID.randomUUID(), name, amount, AttributeModifier.Operation.valueOf(operation), slot )); } } return meta; }
Example #20
Source File: Utils.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * 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 #21
Source File: ArrowTurret.java From Civs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { if (event.isCancelled()) { return; } Entity projectile = event.getDamager(); if (!(projectile instanceof Arrow) || !(event.getEntity() instanceof Player)) { return; } Arrow arrow = (Arrow) projectile; Player damagee = (Player) event.getEntity(); double maxHP = damagee.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); //TODO check to make sure this works if (arrowDamages.get(arrow) == null) { return; } //String ownerName = arrowOwners.get(arrow); //Player player = null; //if (ownerName != null) { // player = Bukkit.getPlayer(ownerName); //} int damage = (int) ((double) arrowDamages.get(arrow) / 100.0 * maxHP); arrowDamages.remove(arrow); //arrowOwners.remove(arrow); //if (player != null) { // damagee.damage(damage, player); //} else { // damagee.damage(damage); //damagee.damage(damage); //} // event.setCancelled(true); damage = DamageEffect.adjustForArmor(damage, damagee); event.setDamage(damage); }
Example #22
Source File: CivilianListener.java From Civs with GNU General Public License v3.0 | 5 votes |
@EventHandler @SuppressWarnings("unused") public void onCivilianQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); Civilian civilian = CivilianManager.getInstance().getCivilian(uuid); if (civilian.isInCombat() && ConfigManager.getInstance().getCombatLogPenalty() > 0) { int penalty = (int) (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() * ConfigManager.getInstance().getCombatLogPenalty() / 100); if (civilian.getLastDamager() != null) { Player damager = Bukkit.getPlayer(civilian.getLastDamager()); if (damager != null && damager.isOnline()) { player.damage(penalty); } } else { player.damage(penalty); } } CivilianManager.getInstance().unloadCivilian(player); CommonScheduler.getLastRegion().remove(uuid); CommonScheduler.getLastTown().remove(uuid); CommonScheduler.removeLastAnnouncement(uuid); MenuManager.clearHistory(uuid); MenuManager.clearData(uuid); TownManager.getInstance().clearInvite(uuid); AnnouncementUtil.clearPlayer(uuid); StructureUtil.removeBoundingBox(uuid); }
Example #23
Source File: PWIPlayerManager.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Updates all the values of a player in the cache. * * @param newData The current snapshot of the Player * @param currentPlayer The PWIPlayer currently in the cache */ public void updateCache(Player newData, PWIPlayer currentPlayer) { ConsoleLogger.debug("Updating player '" + newData.getName() + "' in the cache"); currentPlayer.setSaved(false); currentPlayer.setArmor(newData.getInventory().getArmorContents()); currentPlayer.setEnderChest(newData.getEnderChest().getContents()); currentPlayer.setInventory(newData.getInventory().getContents()); currentPlayer.setCanFly(newData.getAllowFlight()); currentPlayer.setDisplayName(newData.getDisplayName()); currentPlayer.setExhaustion(newData.getExhaustion()); currentPlayer.setExperience(newData.getExp()); currentPlayer.setFlying(newData.isFlying()); currentPlayer.setFoodLevel(newData.getFoodLevel()); if (checkServerVersion(plugin.getServer().getVersion(), 1, 9, 0)) { currentPlayer.setMaxHealth(newData.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue()); } else { currentPlayer.setMaxHealth(newData.getMaxHealth()); } currentPlayer.setHealth(newData.getHealth()); currentPlayer.setLevel(newData.getLevel()); currentPlayer.setSaturationLevel(newData.getSaturation()); currentPlayer.setPotionEffects(newData.getActivePotionEffects()); currentPlayer.setFallDistance(newData.getFallDistance()); currentPlayer.setFireTicks(newData.getFireTicks()); currentPlayer.setMaxAir(newData.getMaximumAir()); currentPlayer.setRemainingAir(newData.getRemainingAir()); if (plugin.getEconomy() != null) { currentPlayer.setBankBalance(plugin.getEconomy().bankBalance(newData.getName()).balance); currentPlayer.setBalance(plugin.getEconomy().getBalance(newData)); } }
Example #24
Source File: HealEffect.java From Civs with GNU General Public License v3.0 | 5 votes |
@Override public HashMap<String, Double> getVariables() { Object target = getTarget(); HashMap<String, Double> returnMap = new HashMap<>(); if (!(target instanceof LivingEntity)) { return returnMap; } LivingEntity livingEntity = (LivingEntity) target; returnMap.put("health", livingEntity.getHealth()); returnMap.put("maxHealth", livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); return returnMap; }
Example #25
Source File: PWIPlayer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
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 #26
Source File: PWIPlayerManager.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Updates all the values of a player in the cache. * * @param newData The current snapshot of the Player * @param currentPlayer The PWIPlayer currently in the cache */ public void updateCache(Player newData, PWIPlayer currentPlayer) { ConsoleLogger.debug("Updating player '" + newData.getName() + "' in the cache"); currentPlayer.setSaved(false); currentPlayer.setArmor(newData.getInventory().getArmorContents()); currentPlayer.setEnderChest(newData.getEnderChest().getContents()); currentPlayer.setInventory(newData.getInventory().getContents()); currentPlayer.setCanFly(newData.getAllowFlight()); currentPlayer.setDisplayName(newData.getDisplayName()); currentPlayer.setExhaustion(newData.getExhaustion()); currentPlayer.setExperience(newData.getExp()); currentPlayer.setFlying(newData.isFlying()); currentPlayer.setFoodLevel(newData.getFoodLevel()); if (checkServerVersion(plugin.getServer().getVersion(), 1, 9, 0)) { currentPlayer.setMaxHealth(newData.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue()); } else { currentPlayer.setMaxHealth(newData.getMaxHealth()); } currentPlayer.setHealth(newData.getHealth()); currentPlayer.setLevel(newData.getLevel()); currentPlayer.setSaturationLevel(newData.getSaturation()); currentPlayer.setPotionEffects(newData.getActivePotionEffects()); currentPlayer.setFallDistance(newData.getFallDistance()); currentPlayer.setFireTicks(newData.getFireTicks()); currentPlayer.setMaxAir(newData.getMaximumAir()); currentPlayer.setRemainingAir(newData.getRemainingAir()); if (plugin.getEconomy() != null) { currentPlayer.setBankBalance(plugin.getEconomy().bankBalance(newData.getName()).balance); currentPlayer.setBalance(plugin.getEconomy().getBalance(newData)); } }
Example #27
Source File: MaxHealthBoost.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void playerLogin(PlayerLoginEvent event) { new BukkitRunnable() { @Override public void run() { if (!PlayerData.playerMaxGuildRank.containsKey(event.getPlayer().getUniqueId())) return; if (PlayerData.playerMaxGuildRank.get(event.getPlayer().getUniqueId()) < 11) return; event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue((PlayerData.playerMaxGuildRank.get(event.getPlayer().getUniqueId()) - 10) * 2 + 20); } }.runTaskLater(MetadataHandler.PLUGIN, 5); }
Example #28
Source File: TrashMobEntity.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
public TrashMobEntity(EntityType entityType, Location location, String name) { super(entityType, location, 1, name, CreatureSpawnEvent.SpawnReason.CUSTOM); super.setHasCustomHealth(true); super.getLivingEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(1); super.getLivingEntity().setHealth(1); super.setHasSpecialLoot(false); }
Example #29
Source File: EntityUtil.java From AACAdditionPro with GNU General Public License v3.0 | 5 votes |
/** * Gets the maximum health of an {@link LivingEntity}. */ public static double getMaxHealth(LivingEntity livingEntity) { switch (ServerVersion.getActiveServerVersion()) { case MC188: return livingEntity.getMaxHealth(); case MC112: case MC113: case MC114: case MC115: return Objects.requireNonNull((livingEntity).getAttribute(Attribute.GENERIC_MAX_HEALTH), "Tried to get max health of an entity without health.").getValue(); default: throw new UnknownMinecraftVersion(); } }
Example #30
Source File: Players.java From CardinalPGM with MIT License | 5 votes |
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)); }