public static PVPMode getPVPMode(Player player){ Objects.requireNonNull(player, "player cannot be null!"); return player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).getBaseValue() == 4 ? PVPMode.NEW_PVP : PVPMode.OLD_PVP; }
Player p = new Player(); p.set("name","john"); p.set("health",42); System.out.println(p.getAttribute("name") +"'s health is " + p.getAttribute("health"));
@Override public double getSprintAttributeMultiplier(final Player player) { final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST); return mod == null ? 1.0 : getMultiplier(mod); }
@Override public PowerResult<Void> fire(Player player, ItemStack stack, LivingEntity entity, Double damage) { if (random.nextInt(chance) == 0 && damage != null) { if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); player.setHealth(Math.max(Math.min(player.getHealth() + damage * factor, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()), 0.01)); return PowerResult.ok(); } return PowerResult.noop(); }
@Override public double getSpeedAttributeMultiplier(final Player player) { final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); final double val = attrInst.getValue() / attrInst.getBaseValue(); final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST); return mod == null ? val : (val / getMultiplier(mod)); }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (!player.isSprinting()) return PowerResult.noop(); double originDamage = damage; damage = damage * (1 + percentage / 100.0); damage = damage + damage * (player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getValue() / 0.13 - 1) * (speedPercentage / 100.0); damage = Math.max(Math.min(damage, cap), originDamage); event.setDamage(damage); if (damage > originDamage) { player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_LAND, 0.1f, 0.1f); } return PowerResult.ok(damage); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerQuit(PlayerQuitEvent e){ Player player = e.getPlayer(); AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(baseValue != 4){ //If basevalue is not 1.9 default, set it back attribute.setBaseValue(4); player.saveData(); } }
/** * Gives an increased max health reward to a player. * * @param player * @param amount * @return the reward text to display to the player */ @SuppressWarnings("deprecation") private String rewardMaxHealth(Player player, int amount) { if (serverVersion >= 9) { AttributeInstance playerAttribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); playerAttribute.setBaseValue(playerAttribute.getBaseValue() + amount); } else { player.setMaxHealth(player.getMaxHealth() + amount); } return ChatColor.translateAlternateColorCodes('&', StringUtils.replaceOnce(langIncreaseMaxHealthRewardReceived, "AMOUNT", Integer.toString(amount))); }
private void checkAttackSpeed(Player player){ World world = player.getWorld(); //If module is disabled, set attack speed to 1.9 default double attackSpeed = Config.moduleEnabled("disable-attack-cooldown", world) ? module().getDouble("generic-attack-speed") : 4; AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(baseValue != attackSpeed){ attribute.setBaseValue(attackSpeed); player.saveData(); } }
oldFoodLevel = player.getFoodLevel(); if (is1_9) { oldMaxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
public void storePlayerData(){ ItemStack[] storedItems = player.getInventory().getContents(); ItemStack[] storedArmour = player.getInventory().getArmorContents(); int food = player.getFoodLevel(); double health = player.getHealth(); float saturation = player.getSaturation(); lastScoreboard = player.getScoreboard(); GameMode lastGM = player.getGameMode(); float exp = player.getExp(); if (exp < 0){ Minigames.log.warning("Player Experience was less that 0: " + player.getDisplayName()+ " " + player.getExp()); exp = 0; } int level = player.getLevel(); player.setSaturation(15); player.setFoodLevel(20); player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue()); player.getInventory().clear(); player.getInventory().setArmorContents(null); player.setLevel(0); player.setExp(0); oply = new OfflineMinigamePlayer(getPlayer().getUniqueId().toString(), storedItems, storedArmour, food, health, saturation, lastGM, exp, level, null); player.updateInventory(); }
double GAS = plugin.getConfig().getDouble("disable-attack-cooldown.generic-attack-speed"); AttributeInstance attribute = p.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); String message = "&1[OCM] &aAttack cooldown ";
@EventHandler(priority = EventPriority.HIGHEST) public void onRegen(EntityRegainHealthEvent e){ if(e.getEntityType() != EntityType.PLAYER || e.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED){ return; } final Player p = (Player) e.getEntity(); if(!isEnabled(p.getWorld())) return; e.setCancelled(true); long currentTime = System.currentTimeMillis() / 1000; long lastHealTime = getLastHealTime(p); if(currentTime - lastHealTime < module().getLong("frequency")) return; double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); if(p.getHealth() < maxHealth){ p.setHealth(MathHelper.clamp(p.getHealth() + module().getInt("amount"), 0.0, maxHealth)); healTimes.put(p.getUniqueId(), currentTime); disableSpartanRegenCheck(p); } final float previousExhaustion = p.getExhaustion(); final float exhaustionToApply = (float) module().getDouble("exhaustion"); Bukkit.getScheduler().runTaskLater(plugin, () -> { //This is because bukkit doesn't stop the exhaustion change when cancelling the event p.setExhaustion(previousExhaustion + exhaustionToApply); debug("Exhaustion before: " + previousExhaustion + " Now: " + p.getExhaustion() + " Saturation: " + p.getSaturation(), p); }, 1L); }
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { double mh = scanned.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); double health = scanned.getHealth() / mh * scanned.getHealthScale(); float hunger = (scanned.getFoodLevel() / 20F) * 100;
double mh = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); player.setHealth(mh / 10.0d); if (inv) {
public void revertToCheckpoint(MinigamePlayer player) { RevertCheckpointEvent event = new RevertCheckpointEvent(player); Bukkit.getServer().getPluginManager().callEvent(event); if(!event.isCancelled()){ player.teleport(player.getCheckpoint()); player.addRevert(); player.sendInfoMessage(MinigameUtils.getLang("player.checkpoint.revert")); // Reset the player's health and extinguish flames when they revert Player p = player.getPlayer(); if ((p != null) && (p.isOnline())) { p.setFireTicks(0); p.setHealth(p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); p.setFoodLevel(20); p.setSaturation(20f); p.setRemainingAir(p.getMaximumAir()); } } }
player.setExp(data.getOldExp()); if (is1_9) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(data.getOldMaxHealth()); player.setHealth(data.getOldHealth() <= data.getOldMaxHealth() ? data.getOldHealth() : data.getOldMaxHealth()); } else {
double mh = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); player.setHealth(mh / 10.0d); if (inv) {
@Override public PowerResult<Void> tick(Player player, ItemStack stack) { if (!checkCooldownByString(this, player, "potiontick." + effect.getName(), interval, false, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); double health = player.getHealth(); boolean hasEffect = false; for (PotionEffect potionEffect : player.getActivePotionEffects()) { if (potionEffect.getType().equals(effect)) { hasEffect = true; if (clear) { player.removePotionEffect(effect); } else if (potionEffect.getDuration() <= 5 || potionEffect.getAmplifier() < amplifier) player.addPotionEffect(new PotionEffect(effect, duration, amplifier, true), true); break; } } if (!hasEffect && !clear) { player.addPotionEffect(new PotionEffect(effect, duration, amplifier, true), true); } if (effect.equals(PotionEffectType.HEALTH_BOOST) && health > 0) { health = min(health, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); player.setHealth(health); } return PowerResult.ok(); }
event.setCancelled(true); try { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); } catch (LinkageError e) { player.setHealth(player.getMaxHealth());