本文整理汇总了Java中org.bukkit.attribute.AttributeInstance类的典型用法代码示例。如果您正苦于以下问题:Java AttributeInstance类的具体用法?Java AttributeInstance怎么用?Java AttributeInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttributeInstance类属于org.bukkit.attribute包,在下文中一共展示了AttributeInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyToBattle
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
/**
* 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));
}
}
示例2: onPlayerLogin
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
@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();
}
}
示例3: onWorldChange
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
@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();
}
}
示例4: mockPlayer
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
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;
}
示例5: onSpawn
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
@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());
}
}
示例6: addModifier0
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
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;
}
示例7: removeModifier0
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
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;
}
示例8: getAttribute
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
@Override
public AttributeInstance getAttribute(Attribute attribute)
{
if (attributes.containsKey(attribute))
{
return attributes.get(attribute);
}
else
{
throw new UnimplementedOperationException();
}
}
示例9: DungeonBoss
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
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.
}
示例10: clearStats
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
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);
}
}
示例11: onPlayerJoin
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
@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);
}
}
示例12: onPlayerQuit
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
@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();
}
}
示例13: setAttributeModifier
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
/**
* 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));
}
示例14: rewardMaxHealth
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
/**
* 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)));
}
示例15: onEntityTargetPlayer
import org.bukkit.attribute.AttributeInstance; //导入依赖的package包/类
public static void onEntityTargetPlayer(EntityTargetLivingEntityEvent event) {
if (event.getTarget() instanceof Player) {
Player player = (Player) event.getTarget();
if (event.getEntity() instanceof LivingEntity) {
LivingEntity attacker = (LivingEntity) event.getEntity();
if ((event.getEntity().getCustomName() != null) && (player.getName() != null)) {
if (event.getEntity().getCustomName().startsWith(player.getName())) {
//we are attacking our creator
if (attacker.getHealth() < (player.getLevel() + 1.0f) * player.getHealth() * 0.05f) {
event.setCancelled(true);
} //make minions not harm their creators if the creators are tough enough
//level 20 will do it for normal 20 heart mobs. Assumes you're not injured.
} else {
//we're attacking a player that's not our creator
AttributeInstance speedAttribute = attacker.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
if (speedAttribute.getValue() > Math.sqrt(player.getLevel())) {
event.setCancelled(true);
} //ultra hyper mobs are seeking high level players
if ((attacker.getHealth()) > ((player.getLevel() + 1.0f) * player.getHealth())) {
event.setCancelled(true);
}//mobs try to get you down to level*health is less than their health.
//If you're level 0, almost any damage ought to make them relent
//If you're over level 20, you'll be dead before they trust you.
}
} else {
if ((attacker.getHealth()) > ((player.getLevel() + 1.0f) * player.getHealth())) {
event.setCancelled(true);
}//mobs try to get you down to level*health is less than their health.
//If you're level 0, almost any damage ought to make them relent
//If you're over level 20, you'll be dead before they trust you.
}
}
}
}