本文整理汇总了Java中org.bukkit.entity.Horse.getInventory方法的典型用法代码示例。如果您正苦于以下问题:Java Horse.getInventory方法的具体用法?Java Horse.getInventory怎么用?Java Horse.getInventory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Horse
的用法示例。
在下文中一共展示了Horse.getInventory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equip
import org.bukkit.entity.Horse; //导入方法依赖的package包/类
@Override
public boolean equip(Entity entity, ItemStack item) {
PreCon.notNull(entity);
PreCon.notNull(item);
if (!(entity instanceof Horse))
return false;
Horse horse = (Horse)entity;
HorseInventory inventory = horse.getInventory();
Material material = item.getType();
if (material == Material.SADDLE) {
inventory.setSaddle(item);
}
else {
if (Materials.hasProperty(material, MaterialProperty.HORSE_ARMOR)) {
inventory.setArmor(item);
}
else {
return false;
}
}
return true;
}
示例2: clear
import org.bukkit.entity.Horse; //导入方法依赖的package包/类
@Override
public List<ItemStack> clear(Entity entity) {
PreCon.notNull(entity);
if (!(entity instanceof Horse))
return new ArrayList<>(0);
Horse horse = (Horse)entity;
HorseInventory inventory = horse.getInventory();
List<ItemStack> result = new ArrayList<>(2);
ItemStack saddle = inventory.getSaddle();
if (saddle != null) {
result.add(saddle);
inventory.setSaddle(null);
}
ItemStack armor = inventory.getArmor();
if (armor != null) {
result.add(armor);
inventory.setArmor(null);
}
return result;
}
示例3: StoredEntity
import org.bukkit.entity.Horse; //导入方法依赖的package包/类
StoredEntity(final SharedTablesModule module, final Entity entity) {
this.module = module;
this.id = StoredEntity.TEMP_ID;
this.type = module.getEntityType(entity).orElseThrow(() -> new IllegalStateException("Missing storedentitytype for entity type " + entity.getType().toString()));
if (entity.getCustomName() != null) { this.name = Optional.of(module.getOrCreateText(entity.getCustomName())); }
else { this.name = Optional.empty(); }
if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity) entity;
this.maxHP = Optional.of(living.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
}
else { this.maxHP = Optional.empty(); }
if (entity instanceof Wolf) {
final Wolf wolf = (Wolf) entity;
this.color = Optional.of(module.getColor(wolf.getCollarColor().name()).orElseThrow(() -> new NoSuchElementException("Failed to find color " + wolf.getCollarColor().name())));
this.horseStrength = Optional.empty();
this.armorType = Optional.empty();
}
else if (entity instanceof Sheep) {
final Sheep sheep = (Sheep) entity;
this.color = Optional.of(module.getColor(sheep.getColor().name()).orElseThrow(() -> new NoSuchElementException("Failed to find color " + sheep.getColor().name())));
this.horseStrength = Optional.empty();
this.armorType = Optional.empty();
}
else if (entity instanceof Horse) {
final Horse horse = (Horse) entity;
if (horse.getColor() != null) { this.color = Optional.of(module.getColor(horse.getColor().name()).orElseThrow(() -> new NoSuchElementException("Failed to find color " + horse.getColor().name()))); }
else { this.color = Optional.empty(); }
if (horse.getInventory() != null && horse.getInventory().getArmor() != null && horse.getInventory().getArmor().getType() != null) {
final Material armorTypeItem = horse.getInventory().getArmor().getType();
this.armorType = Optional.of(module.getArmor(armorTypeItem).orElseThrow(() -> new NoSuchElementException("Failed to find armortype for armor " + armorTypeItem.name())));
}
else { this.armorType = Optional.empty(); }
this.horseStrength = Optional.of(horse.getJumpStrength());
}
else {
this.color = Optional.empty();
this.horseStrength = Optional.empty();
this.armorType = Optional.empty();
}
final int uuidId = module.getDatabase().getUniqueIdStorage().getOrCreateId(entity.getUniqueId());//.orElseThrow(() -> new NoSuchElementException("Failed to retrieve storeduuid for entity " + entity.getUniqueId()));
this.uniqueId = new StoredUUID(uuidId, entity.getUniqueId());
this.createdAt = Instant.now();
}
示例4: update
import org.bukkit.entity.Horse; //导入方法依赖的package包/类
/**
* Updates the attributes of this {@link StoredEntity} instance based on the given entity.
* Note that the entity type of this instance will not be changed.
* @param entity The entity to take the attributes from.
*/
public void update(final Entity entity) {
Check.notNull(entity, "The entity in StoredEntity#update(Entity) cannot be null!");
// Update displayname
if (entity.getCustomName() != null) { this.name = Optional.of(this.module.getOrCreateText(entity.getCustomName())); }
else { this.name = Optional.empty(); }
// Update max hp
if (entity instanceof LivingEntity) { this.maxHP = Optional.of(((LivingEntity)entity).getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); }
else { this.maxHP = Optional.empty(); }
// Update color
this.color = Optional.empty();
this.armorType = Optional.empty();
this.horseStrength = Optional.empty();
if (entity instanceof Wolf) {
final Wolf wolf = (Wolf) entity;
this.color = Optional.of(this.module.getColor(wolf.getCollarColor().name()).orElseThrow(() -> new NoSuchElementException("Failed to find color " + wolf.getCollarColor().name())));
}
else if (entity instanceof Sheep) {
final Sheep sheep = (Sheep) entity;
this.color = Optional.of(this.module.getColor(sheep.getColor().name()).orElseThrow(() -> new NoSuchElementException("Failed to find color " + sheep.getColor().name())));
}
else if (entity instanceof Horse) {
final Horse horse = (Horse) entity;
if (horse.getColor() != null) { this.color = Optional.of(this.module.getColor(horse.getColor().name()).orElseThrow(() -> new NoSuchElementException("Failed to find color " + horse.getColor().name()))); }
else { this.color = Optional.empty(); }
// Update armor
if (horse.getInventory() != null && horse.getInventory().getArmor() != null && horse.getInventory().getArmor().getType() != null) {
final Material armorTypeItem = horse.getInventory().getArmor().getType();
this.armorType = Optional.of(this.module.getArmor(armorTypeItem).orElseThrow(() -> new NoSuchElementException("Failed to find armortype for armor " + armorTypeItem.name())));
}
else { this.armorType = Optional.empty(); }
// Update horse jump strength
this.horseStrength = Optional.of(horse.getJumpStrength());
}
// Update uuid
if (!this.uniqueId.get().equals(entity.getUniqueId())) {
final int uuidId = this.module.getDatabase().getUniqueIdStorage().getOrCreateId(entity.getUniqueId());//.orElseThrow(() -> new NoSuchElementException("Failed to retrieve storeduuid for entity " + entity.getUniqueId()));
this.uniqueId = new StoredUUID(uuidId, entity.getUniqueId());
}
}
示例5: horseEnter
import org.bukkit.entity.Horse; //导入方法依赖的package包/类
@EventHandler
public void horseEnter(VehicleEnterEvent event){
if(event.getVehicle() instanceof Horse){
EntityType entered = (EntityType)event.getEntered().getType();
if(entered == EntityType.PLAYER){ //Playercheck
Player p = (Player)event.getEntered();
String playername = p.getName();
@SuppressWarnings("unused")
Server server = p.getServer(); //Not used for now
Horse h = (Horse)event.getVehicle();
AnimalTamer owner = h.getOwner();
HashMap<String, ArrayList<Block>> map = ECHorses.hashmap; //Getting hashmap from main class
if(map.containsKey(playername)){ //If player has done /horseunclaim, then when the player left click the horse, unclaim the horse.
if(owner == null){
p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.GREEN + " Nobody owns this horse!");
return;
}
if(!(owner == null)){
if(p.isOp() || p.hasPermission("echorse.override")){
p.sendMessage("You are overriding horse protection!");
h.setOwner(null); //Removing horse claim (untame horse)
map.remove(playername); //Remove the player from hashmap.
return;
}
if(h.getOwner().getName() == p.getName()){ //Owner check
Location loc = h.getLocation().clone();
Inventory inv = h.getInventory();
for (ItemStack item : inv.getContents()){ //Checking if the horse has saddle & armor & or something its inventory (Donkey)
if(item!= null){
loc.getWorld().dropItemNaturally(loc, item.clone()); //Drops all the inventory contents on the horse location ground.
}
}
inv.clear(); //Clears the inventory of the horse.
if(h.isCarryingChest()){ //If the horse is carrying a chest (Donkey)
h.setCarryingChest(false); //if true then remove the chest.
}
h.setOwner(null); //Remove horse claim (untame horse.)
p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.GOLD + " Successfully removed horse protection. (Horse is not tamed anymore)");
map.remove(playername); //Remove the player from hashmap.
event.setCancelled(true);
return;
}
}
}
//Horse stealing protection (Entering the horse)
if(!(owner == null)){
if(p.isOp() || p.hasPermission("echorse.override")){ //Overriding the protection if player is OP
return;
}
if(h.getOwner().getName() == p.getName()){ //Checking if entering player is the owner
return;
}
else {
p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.RED + " This horse is owned by " + h.getOwner().getName());
Bukkit.getLogger().info("[ECHorses] " + playername + " tried entering someone elses horse");
event.setCancelled(true);
return;
}
}
p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.GREEN + " This horse is untamed!");
}
}
}