@EventHandler public void onRegen(EntityRegainHealthEvent event) { if (event.getEntityType() != EntityType.PLAYER || event.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED) return; event.setCancelled(true); Player player = (Player) event.getEntity(); long currentTime = System.currentTimeMillis() / 1000; if (currentTime - getLastHealTime(player) < 3) return; double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); if (player.getHealth() < maxHealth) { player.setHealth(clamp(player.getHealth() + 1, 0.0, maxHealth)); healTimes.put(player.getUniqueId(), currentTime); } float exhToApply = (float) 3; Bukkit.getScheduler().runTaskLater(TGM.get(), () -> { //This is because bukkit doesn't stop the exhaustion change when cancelling the event player.setExhaustion(player.getExhaustion() + exhToApply); //debug("Exhaustion before: " + previousExh + " Now: " + p.getExhaustion() + "Saturation: " + p.getSaturation(), p); }, 1L); }
private void createHorse(Player player, Location spawn) { player.teleport(spawn); Horse horse = spawn.getWorld().spawn(spawn, Horse.class); horse.setJumpStrength(0); double speed = this.getAPI().getGameManager().getGameState() == GameState.STARTING ? 0D : 0.7D; // TODO Fix this for 1.8 horse.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(speed); Bukkit.getScheduler().runTaskLater(getAPI().getPlugin(), () -> { horse.addPassenger(player); horse.setTamed(true); horse.getInventory().setSaddle(new ItemStack(Material.SADDLE)); horse.setAdult(); horse.setOwner(player); }, 1L); }
private void spawnZombie() { Location center = new Location(Parties.getPartyWorld(), -74.5, 76, 30); Zombie z = center.getWorld().spawn(Utils.scatter(center, 4, 0, 4), Zombie.class); z.setCustomNameVisible(true); z.setCustomName(ChatColor.RED + "Piñata"); z.getEquipment().setHelmet(ItemManager.createSkull("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZn" + "QubmV0L3RleHR1cmUvM2IyNTI2NmQ0MGNlY2Q5M2QwNTMxNTZlNGE0YTc4NDE0MGQwMzQyNTVjNzIxY2MzNzVkMWMzNjQ4MzQyYjZmZCJ9fX0", "Pinata Skull", "He doesn't want to party anymore.")); z.getEquipment().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE)); z.getEquipment().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS)); z.getEquipment().setBoots(new ItemStack(Material.LEATHER_BOOTS)); z.getEquipment().setItemInMainHand(ItemManager.createItem(Material.STICK, ChatColor.RED + "Pinata Bat", ChatColor.DARK_PURPLE + "Stop hitting me!")); z.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(40); z.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(.4F); z.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).setBaseValue(6); z.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).setBaseValue(1); z.setSilent(true); z.setGlowing(true); getScheduler().runTaskLater(z::remove, 1200L); // Remove zombie in 1 minute. }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) // Handle dungeon death. public void onPlayerDeath(PlayerDeathEvent evt) { if (!isDungeon(evt.getEntity())) return; evt.setKeepLevel(true); // Keep XP, but drop inventory. (Since you can't bring anything in) Player p = evt.getEntity(); makeCorpse(p); p.setHealth(p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); // Restore to max health. p.setGameMode(GameMode.SPECTATOR); // Set to spectator. p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 50, 2)); // Give blindness. p.sendTitle(new Title(ChatColor.RED + "Dungeon Failed")); getDungeon(p).alert(p.getName() + " has been eliminated."); Utils.stopNBS(p); //Disable music. Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { Utils.toSpawn(p); // Teleport to spawn. p.setGameMode(GameMode.SURVIVAL); }, 50L); }
/** * Apply this templates data to an EnderDragonBattle object * * @param nmsAbstract an instance of the NMSAbstract interface * @param dragon the dragon to modify * @param battle the battle to modify */ public void applyToBattle(NMSAbstract nmsAbstract, EnderDragon dragon, DragonBattle battle) { Validate.notNull(nmsAbstract, "Instance of NMSAbstract cannot be null. See DragonEggDrop#getNMSAbstract()"); Validate.notNull(dragon, "Ender Dragon cannot be null"); Validate.notNull(battle, "Instance of DragonBattle cannot be null"); if (name != null) { dragon.setCustomName(name); battle.setBossBarTitle(name); } battle.setBossBarStyle(barStyle, barColour); this.attributes.forEach((a, v) -> { AttributeInstance attribute = dragon.getAttribute(a); if (attribute != null) { attribute.setBaseValue(v); } }); // Set health... max health attribute doesn't do that for me. -,- if (attributes.containsKey(Attribute.GENERIC_MAX_HEALTH)) { dragon.setHealth(attributes.get(Attribute.GENERIC_MAX_HEALTH)); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerLogin(PlayerJoinEvent e) { Player p = e.getPlayer(); World world = p.getWorld(); double GAS = module().getDouble("generic-attack-speed"); AttributeInstance attribute = p.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(!Config.moduleEnabled("disable-attack-cooldown", world)) GAS = 4; //If module is disabled, set attack speed to 1.9 default if(baseValue!=GAS){ attribute.setBaseValue(GAS); p.saveData(); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onWorldChange(PlayerChangedWorldEvent e) { Player player = e.getPlayer(); World world = player.getWorld(); double GAS = module().getDouble("generic-attack-speed"); AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(!Config.moduleEnabled("disable-attack-cooldown", world)) GAS = 4; //If module is disabled, set attack speed to 1.9 default if(baseValue!=GAS){ attribute.setBaseValue(GAS); player.saveData(); } }
@EventHandler public void onCombat(CombatEvent e) { Player p = e.getPlayer().getPlayer().getPlayer(); if (!ForgeAction.Repairable.isRepairable(e.getWeapon().getType()) || (e.getWeapon() == null || !SpellHolder.SpellHolderDefinition.isHolder(e.getOtherItem()))) { Skill.setAttributeModifier(p.getAttribute(Attribute.GENERIC_ATTACK_SPEED), MODIFIER_NAME, 0); return; } int lvl = e.getPlayer().getSkillLevel(this); //all we do is modify swing speed (so reduce cooldown) when swinging double rate = (lvl * meleeRate); //we'll subtract this. //bonus attack damage Skill.setAttributeModifier(p.getAttribute(Attribute.GENERIC_ATTACK_SPEED), MODIFIER_NAME, rate); //System.out.println("reported attack speed: " + p.getAttribute(Attribute.GENERIC_ATTACK_SPEED).getBaseValue() + " -> " + p.getAttribute(Attribute.GENERIC_ATTACK_SPEED).getValue()); this.perform(e.getPlayer(), lvl - levelPenalty, e.isMiss()); //only get a 'cause miss' if this skill caused it }
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; }
@EventHandler public void onSpawn(CreatureSpawnEvent event) { LivingEntity e = event.getEntity(); WorldSettings set = plugin.getWorlds().get(event.getEntity().getWorld().getName()); if (set == null) { return; } if (!set.getEntities().contains(e.getType())) { return; } if (!set.shouldExist(e)) { event.setCancelled(true); } else if (rand.nextDouble() > set.getRatio(e.getType())) { event.setCancelled(true); } else { AttributeInstance maxHealth = e.getAttribute(Attribute.GENERIC_MAX_HEALTH); maxHealth.setBaseValue(maxHealth.getBaseValue() * set.getHealth(e.getType())); e.setHealth(e.getMaxHealth()); } }
@EventHandler(priority = EventPriority.MONITOR) public void onEntityDeath(EntityDeathEvent event) { Entity killer = event.getEntity().getKiller(); if (killer instanceof Player) { Player player = (Player) killer; double health = player.getHealth(); double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); if (health > 0.0D && health < maxHealth) { PlayerData data = plugin.getPlayerDataCache().getData(player); int level = data.getLevel(25); if (Util.random(75 / level) == 0) { player.setHealth(Math.min(health + 1.0D, maxHealth)); double heartsStolen = (player.getHealth() - health) / 2; player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("life_steal"), heartsStolen, getName(event.getEntity()))); } } } }
@Override public void onGameStart() { startLine.iterator().forEachRemaining(block -> { block.setType(Material.AIR); }); for(Player player : Bukkit.getOnlinePlayers()) { if(!this.getAPI().getGameManager().isAlive(player)) continue; if(player.getVehicle() != null) { ((Horse) player.getVehicle()).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.7D); } } }
public double getJumpStrength(){ AbstractHorse h; if (!isTamed()) return 1; if (!mu.isHorse(entity) || !mu.isDonkey(entity) || !mu.isMule(entity) || !mu.isZombieHorse(entity) || !mu.isSkeletonHorse(entity)) return 0; h = (AbstractHorse)entity; return h.getAttribute(Attribute.HORSE_JUMP_STRENGTH).getValue(); }
@Override public LuaValue onCalled(Varargs parameters) { String name = parameters.arg(1).tojstring(); Attribute attribute = Attribute.valueOf(name.toUpperCase()); if (attribute == null) { return LuaValue.NIL; } return new AttributeType(player.getAttribute(attribute)); }
private boolean addModifier0(Attribute attribute, AttributeModifier modifier) { final AttributeInstance attributeInstance = player.getAttribute(attribute); if(attributeInstance != null && !attributeInstance.getModifiers().contains(modifier)) { attributeInstance.addModifier(modifier); return true; } return false; }
private boolean removeModifier0(Attribute attribute, AttributeModifier modifier) { AttributeInstance attributeValue = player.getAttribute(attribute); if(attributeValue != null && attributeValue.getModifiers().contains(modifier)) { attributeValue.removeModifier(modifier); return true; } return false; }
@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); }
@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)); }
@Override public boolean matches(IPlayerQuery query) { return query.onlinePlayer() .filter(player -> range.contains(player.getBukkit() .getAttribute(Attribute.GENERIC_LUCK) .getValue())) .isPresent(); }
@Override public void setMaxHealth(double health) { getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(health); if (this.health > health) { this.health = health; } }
@Override public AttributeInstance getAttribute(Attribute attribute) { if (attributes.containsKey(attribute)) { return attributes.get(attribute); } else { throw new UnimplementedOperationException(); } }
public DungeonBoss(Location loc, EntityType type, String name, boolean finalBoss) { super(loc, type, name); this.finalBoss = finalBoss; getBukkit().setCustomName(ChatColor.RED + name); getBukkit().setCustomNameVisible(true); AttributeInstance a = getLiving().getAttribute(Attribute.GENERIC_MAX_HEALTH); a.addModifier(new AttributeModifier("mult", 1, AttributeModifier.Operation.ADD_SCALAR)); // Double boss health. getLiving().setHealth(a.getValue()); // Max out health. }
@Override public void onDamage() { BossStage stage = getStages().getValueSafe(1); LivingEntity le = getLiving(); if (stage == null || stage.getHealthPercent() * le.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() < le.getHealth()) return; // If there isn't a stage queued after this. getStages().pop(); // Remove the current stage. updateStage(); // Update stage. }
private void clearStats() { Player player = this.player.getPlayer(); AttributeInstance speedAttribute = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); AttributeModifier rpgInvModifier = null; for (AttributeModifier modifier : speedAttribute.getModifiers()) { if (modifier.getUniqueId().compareTo(Attributes.SPEED_MODIFIER_ID) == 0) { rpgInvModifier = modifier; } } if (rpgInvModifier != null) { speedAttribute.removeModifier(rpgInvModifier); } }
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); if (api.getGameManager().isLegacyPvP()) { AttributeInstance genericAttackSpeedAttribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); if (genericAttackSpeedAttribute != null) genericAttackSpeedAttribute.setBaseValue(1024.0D); } }
/** * Reset any player stats and such. */ @SuppressWarnings("all") public void reset() { Class craftPlayer = ReflectionUtils.getClazz(ReflectionUtils.cbclasses, "CraftPlayer"); Class entityHuman = ReflectionUtils.getClazz(ReflectionUtils.nmsclasses, "EntityHuman"); Class entity = ReflectionUtils.getClazz(ReflectionUtils.nmsclasses, "Entity"); Class playerAbilities = ReflectionUtils.getClazz(ReflectionUtils.nmsclasses, "PlayerAbilities"); try { Object nmsPlayer = craftPlayer.getDeclaredMethod("getHandle").invoke(bukkit); entityHuman.getDeclaredField("abilities").set(nmsPlayer, playerAbilities.getConstructor().newInstance()); entityHuman.getDeclaredMethod("updateAbilities").invoke(nmsPlayer); for (int flag = 0; flag < 7; flag++) entity.getDeclaredMethod("setFlag", int.class, boolean.class).invoke(nmsPlayer, flag, false); } catch (Exception e) { e.printStackTrace(); } update(); Arrays.stream(Attribute.values()).filter(a -> a != Attribute.GENERIC_ATTACK_SPEED && bukkit.getAttribute(a) != null).map(a -> bukkit.getAttribute(a)).forEach(a -> { a.setBaseValue(a.getDefaultValue()); new ArrayList<>(a.getModifiers()).forEach(a::removeModifier); }); bukkit.setExp(0); bukkit.setLevel(0); bukkit.setMaxHealth(20); bukkit.setHealth(bukkit.getMaxHealth()); bukkit.setHealthScale(20); bukkit.setHealthScaled(false); bukkit.setFoodLevel(20); bukkit.setFallDistance(0); bukkit.setSaturation(5f); bukkit.getActivePotionEffects().forEach(a -> bukkit.removePotionEffect(a.getType())); invulnerable = true; new BukkitRunnable() { public void run() { invulnerable = false; } }.runTaskLater(OMGPI.instance, 20L); }
/** * Add an attribute to this template * * @param attribute the attribute to add * @param value the new value of the attribute * @param updateFile whether to update the dragon file or not */ public void addAttribute(Attribute attribute, double value, boolean updateFile) { Validate.notNull(attribute, "Cannot add a null attribute"); if (value < 0.0) value = 0.0; this.attributes.put(attribute, value); if (updateFile) { this.updateConfig("attributes." + attribute.name(), value); } }
/** * Remove an attribute from this template and set its value back to default * * @param attribute the attribute to remove * @param updateFile whether to update the dragon file or not */ public void removeAttribute(Attribute attribute, boolean updateFile) { Validate.notNull(attribute, "Cannot remove a null attribute"); this.attributes.remove(attribute); if (updateFile) { this.updateConfig("attributes." + attribute.name(), null); } }
@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(); } }
@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); } final float PREVIOUS_EXHAUSTION = p.getExhaustion(); final float EXHAUSTION_TO_APPLY = (float) module().getDouble("exhaustion"); Bukkit.getScheduler().runTaskLater(plugin, () -> { //This is because bukkit doesn't stop the exhaustion change when cancelling the event p.setExhaustion(PREVIOUS_EXHAUSTION + EXHAUSTION_TO_APPLY); debug("Exhaustion before: " + PREVIOUS_EXHAUSTION + " Now: " + p.getExhaustion() + " Saturation: " + p.getSaturation(), p); },1L); }
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.setWalkSpeed(0.2F); player.setFlySpeed(0.1F); player.setFallDistance(0); player.setFlying(false); player.setAllowFlight(false); player.setCollidable(true); 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)); }
@EventHandler public void onJoin(PlayerJoinEvent event) { if (Skellett.instance.config.getBoolean("Enable1_8pvp")) { event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(100.0D); } else { event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0D); } }
/** * 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)); } }
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; }
/** * 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)); } }
/** * 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 (plugin.getServerVersion() >= 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))); }