本文整理匯總了Java中org.bukkit.attribute.Attribute類的典型用法代碼示例。如果您正苦於以下問題:Java Attribute類的具體用法?Java Attribute怎麽用?Java Attribute使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Attribute類屬於org.bukkit.attribute包,在下文中一共展示了Attribute類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onRegen
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
@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);
}
示例2: createHorse
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
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);
}
示例3: spawnZombie
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
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.
}
示例4: onPlayerDeath
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
@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);
}
示例5: applyToBattle
import org.bukkit.attribute.Attribute; //導入依賴的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));
}
}
示例6: onPlayerLogin
import org.bukkit.attribute.Attribute; //導入依賴的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();
}
}
示例7: onWorldChange
import org.bukkit.attribute.Attribute; //導入依賴的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();
}
}
示例8: onCombat
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
@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
}
示例9: mockPlayer
import org.bukkit.attribute.Attribute; //導入依賴的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;
}
示例10: onSpawn
import org.bukkit.attribute.Attribute; //導入依賴的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());
}
}
示例11: onEntityDeath
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
@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())));
}
}
}
}
示例12: reset
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
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();
}
示例13: onGameStart
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
@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);
}
}
}
示例14: getJumpStrength
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
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();
}
示例15: onCalled
import org.bukkit.attribute.Attribute; //導入依賴的package包/類
@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));
}