public static AttributeModifier.Operation parseAttributeOperation(Node node, String text) throws InvalidXMLException { switch(text.toLowerCase()) { case "add": return AttributeModifier.Operation.ADD_NUMBER; case "base": return AttributeModifier.Operation.ADD_SCALAR; case "multiply": return AttributeModifier.Operation.MULTIPLY_SCALAR_1; } throw new InvalidXMLException("Unknown attribute modifier operation '" + text + "'", node); }
public static Pair<org.bukkit.attribute.Attribute, AttributeModifier> parseCompactAttributeModifier(Node node, String text) throws InvalidXMLException { final String[] parts = text.split(":"); if(parts.length != 3) { throw new InvalidXMLException("Bad attribute modifier format", node); } return Pair.create( parseAttribute(node, parts[0]), new AttributeModifier( "FromXML", parseNumber(node, parts[2], Double.class), parseAttributeOperation(node, parts[1]) ) ); }
public static Pair<org.bukkit.attribute.Attribute, AttributeModifier> parseAttributeModifier(Element el) throws InvalidXMLException { return Pair.create( parseAttribute(new Node(el)), new AttributeModifier( "FromXML", parseNumber(Node.fromRequiredAttr(el, "amount"), Double.class), parseAttributeOperation(Node.fromAttr(el, "operation"), AttributeModifier.Operation.ADD_NUMBER) ) ); }
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 public void addModifier(AttributeModifier modifier) { // TODO Auto-generated method stub 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. }
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); } }
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)); }
private static List<ItemAttributeModifier> parseAttributes(String attributes) { List<ItemAttributeModifier> list = Lists.newArrayList(); for (String attribute : attributes.split(";")) { String[] attr = attribute.split(":"); list.add(new ItemAttributeModifier(null, new AttributeModifier(UUID.randomUUID(), attr[0], Numbers.parseDouble(attr[2]), getOperation(attr[1])))); } return list; }
public static AttributeModifier.Operation getOperation(String operation) { if (Numbers.isNumber(operation)) { return AttributeModifier.Operation.fromOpcode(Integer.parseInt(operation)); } else { switch (operation.toLowerCase()) { case ("base"): return AttributeModifier.Operation.ADD_SCALAR; case ("multiply"): return AttributeModifier.Operation.MULTIPLY_SCALAR_1; case ("add"): default: return AttributeModifier.Operation.ADD_NUMBER; } } }
/** * Sets the provided attribute up with a modifier by the given name (overwriting one if it exists) * for the given amount. * <b>This is done</b> under the {@link AttributeModifier.Operation#ADD_SCALAR} operation! */ public static void setAttributeModifier(AttributeInstance attribute, String name, double amt) { Collection<AttributeModifier> mods = attribute.getModifiers(); for (AttributeModifier mod : mods) { if (mod.getName().equals(name)) { attribute.removeModifier(mod); break; } } attribute.addModifier(new AttributeModifier(name, amt, AttributeModifier.Operation.ADD_SCALAR)); }
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)); }
private static List<ItemAttributeModifier> parseAttributes(String attributes) { List<ItemAttributeModifier> list = new ArrayList<>(); for (String attribute : attributes.split(";")) { String[] attr = attribute.split(":"); list.add(new ItemAttributeModifier(null, new AttributeModifier(UUID.randomUUID(), attr[0], Double.parseDouble(attr[2]), getOperation(attr[1])))); } return list; }
public static AttributeModifier.Operation getOperation(String operation) { if (NumberUtils.isNumber(operation)) { return AttributeModifier.Operation.fromOpcode(Integer.parseInt(operation)); } else { switch (operation.toLowerCase()) { case("add"): return AttributeModifier.Operation.ADD_NUMBER; case("base"): return AttributeModifier.Operation.ADD_SCALAR; case("multiply"): return AttributeModifier.Operation.MULTIPLY_SCALAR_1; } } return AttributeModifier.Operation.ADD_NUMBER; }
@Override public Collection<AttributeModifier> getModifiers() { List<AttributeModifier> result = new ArrayList<AttributeModifier>(); for (net.minecraft.server.AttributeModifier nms : handle.c()) { result.add(convert(nms)); } return result; }
public static void reset(Player player, boolean heal) { if (heal) player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); 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)}); player.setItemOnCursor(new ItemStack(Material.AIR)); player.getActivePotionEffects().forEach(potionEffect -> { try { player.removePotionEffect(potionEffect.getType()); } catch (NullPointerException ignored) {} }); player.setFireTicks(0); player.setFallDistance(0); player.setTotalExperience(0); player.setExp(0); player.setLevel(0); player.setWalkSpeed(0.2F); player.setFlySpeed(0.1F); player.setSneaking(false); player.setInvulnerable(false); player.setCanPickupItems(true); player.setCollidable(true); player.setFlying(false); player.setAllowFlight(false); player.resetTitle(); 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", 24.000D, AttributeModifier.Operation.ADD_SCALAR)); player.updateInventory(); }
public static AttributeModifier.Operation parseAttributeOperation(Node node) throws InvalidXMLException { return parseAttributeOperation(node, node.getValueNormalize()); }
public static AttributeModifier.Operation parseAttributeOperation(Node node, AttributeModifier.Operation def) throws InvalidXMLException { return node == null ? def : parseAttributeOperation(node); }
public AttributeKit(Pair<Attribute, AttributeModifier> pair) { this(pair.first, pair.second); }
public AttributeKit(Attribute attribute, AttributeModifier modifier) { this.attribute = attribute; this.modifier = modifier; }
public boolean addModifier(Attribute attribute, AttributeModifier modifier) { return modifiers.put(attribute, modifier) && addModifier0(attribute, modifier); }
public boolean removeModifier(Attribute attribute, AttributeModifier modifier) { return modifiers.remove(attribute, modifier) && removeModifier0(attribute, modifier); }
public static void removeModifier(Attributable attributable, AttributeModifier modifier) { for(Attribute attribute : Attribute.values()) { final AttributeInstance instance = attributable.getAttribute(attribute); if(instance != null) instance.removeModifier(modifier); } }
@Override public Collection<AttributeModifier> getModifiers() { // TODO Auto-generated method stub throw new UnimplementedOperationException(); }
@Override public void removeModifier(AttributeModifier modifier) { // TODO Auto-generated method stub throw new UnimplementedOperationException(); }
@Override public void apply(Player player, boolean force) { for (AttributeModifier modifier : attributes) { player.getAttribute(Attribute.byName(modifier.getName())).addModifier(modifier); } }
@Override public void remove(Player player) { for (AttributeModifier modifier : attributes) { player.getAttribute(Attribute.byName(modifier.getName())).removeModifier(modifier); } }
private static ItemAttributeModifier getAttribute(Element attribute) { return new ItemAttributeModifier(getEquipmentSlot(attribute.getAttributeValue("slot", "")), new AttributeModifier(UUID.randomUUID(), attribute.getText(), Double.parseDouble(attribute.getAttributeValue("amount", "0.0")), getOperation(attribute.getAttributeValue("operation", "add")))); }
public AttributeModifierKit(List<AttributeModifier> attributes) { this.attributes = attributes; }
@Override public void apply(Player player, Boolean force) { for (AttributeModifier modifier : attributes) { player.getAttribute(Attribute.byName(modifier.getName())).addModifier(modifier); } }
public static ItemAttributeModifier getAttribute(Element attribute) { return new ItemAttributeModifier(getEquipmentSlot(attribute.getAttributeValue("slot", "")), new AttributeModifier(UUID.randomUUID(), attribute.getText(), Double.parseDouble(attribute.getAttributeValue("amount", "0.0")), getOperation(attribute.getAttributeValue("operation", "add")))); }
@Override public void addModifier(AttributeModifier modifier) { Preconditions.checkArgument(modifier != null, "modifier"); handle.b(convert(modifier)); }
@Override public void removeModifier(AttributeModifier modifier) { Preconditions.checkArgument(modifier != null, "modifier"); handle.c(convert(modifier)); }
private static net.minecraft.server.AttributeModifier convert(AttributeModifier bukkit) { return new net.minecraft.server.AttributeModifier(bukkit.getUniqueId(), bukkit.getName(), bukkit.getAmount(), bukkit.getOperation().ordinal()); }
private static AttributeModifier convert(net.minecraft.server.AttributeModifier nms) { return new AttributeModifier(nms.a(), nms.b(), nms.d(), AttributeModifier.Operation.values()[nms.c()]); }