本文整理汇总了Java中org.bukkit.entity.Tameable.isTamed方法的典型用法代码示例。如果您正苦于以下问题:Java Tameable.isTamed方法的具体用法?Java Tameable.isTamed怎么用?Java Tameable.isTamed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Tameable
的用法示例。
在下文中一共展示了Tameable.isTamed方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInteractEvent
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
@EventHandler
public void onInteractEvent(PlayerInteractEntityEvent e){
RedProtect.get().logger.debug("RPEntityListener - Is PlayerInteractEntityEvent");
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
if (p == null){
return;
}
Location l = e.getRightClicked().getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
Entity et = e.getRightClicked();
if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem)) {
if (et instanceof Tameable){
Tameable tam = (Tameable) et;
if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())){
return;
}
}
e.setCancelled(true);
RPLang.sendMessage(p, "entitylistener.region.cantinteract");
}
}
示例2: onPetDeath
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
@EventHandler
public void onPetDeath(EntityDeathEvent event) {
if (!(event.getEntity() instanceof Tameable)) {
return;
}
Tameable petEntity = (Tameable) event.getEntity();
final OfflinePlayer player;
if (!petEntity.isTamed() || (player = (OfflinePlayer) petEntity.getOwner()) == null || !player.isOnline()) {
return;
}
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
PlayerWrapper playerWrapper = InventoryManager.get(player);
if (petEntity == playerWrapper.getPet()) {
Inventory inventory = playerWrapper.getInventory();
final ItemStack petItem = inventory.getItem(PetManager.getPetSlotId());
PetType petType = PetManager.getPetFromItem(petItem);
if (petType != null && petType.isRevival()) {
PetManager.saveDeathTime(petItem);
PetManager.saveHealth(petItem, 0);
inventory.setItem(PetManager.getPetSlotId(), petItem);
PetManager.startCooldownTimer(player.getPlayer(), petItem);
} else {
inventory.setItem(PetManager.getPetSlotId(), null);
}
event.getDrops().clear();
playerWrapper.setPet(null);
}
}
示例3: onEntityDamage
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event)
{
Entity entity = event.getEntity();
if(!(entity instanceof Tameable)) return;
Tameable tameable = (Tameable)entity;
if(!tameable.isTamed() || tameable.getOwner() == null) return;
Flag flag = this.GetFlagInstanceAtLocation(entity.getLocation(), null);
if(flag != null)
{
event.setCancelled(true);
}
}
示例4: getWolves
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
/**
* Gets player's tamed wolves
* @return
*/
public List<Wolf> getWolves() {
List<Wolf> entities = new ArrayList<Wolf>();
for (Entity e : player.getNearbyEntities(ATTACK_RANGE, ATTACK_RANGE, ATTACK_RANGE)) {
if (e instanceof Wolf && e instanceof Tameable) {
Tameable t = (Tameable) e;
if (t.isTamed() && t.getOwner() == this.player) {
entities.add((Wolf) e);
}
}
}
return entities;
}
示例5: isTamed
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
public static boolean isTamed(LivingEntity ent) {
if (ent instanceof Tameable) {
Tameable t = (Tameable) ent;
if (t.isTamed()) return true;
}
return false;
}
示例6: beastLore
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
/**
* Handle the Beast Lore ability.
*
* @param target The entity to examine
*/
public void beastLore(LivingEntity target) {
Player player = getPlayer();
Tameable beast = (Tameable) target;
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
if (beast.isTamed() && beast.getOwner() != null) {
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", beast.getOwner().getName()) + " ");
}
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", target.getHealth(), target.getMaxHealth()));
player.sendMessage(message);
}
示例7: isFriendlyPet
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
/**
* Checks to see if an entity is currently friendly toward a given player.
*
* @param attacker The player to check.
* @param pet The entity to check.
* @return true if the entity is friendly, false otherwise
*/
public static boolean isFriendlyPet(Player attacker, Tameable pet) {
if (pet.isTamed()) {
AnimalTamer tamer = pet.getOwner();
if (tamer instanceof Player) {
Player owner = (Player) tamer;
return (owner == attacker || PartyManager.inSameParty(attacker, owner) || PartyManager.areAllies(attacker, owner));
}
}
return false;
}
示例8: TameableAnimal
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
public TameableAnimal (Entity entity) {
PreCon.notNull(entity);
PreCon.isValid(entity instanceof Tameable, "entity meust be an instance of Tameable");
Tameable tameable = (Tameable)entity;
_isTamed = tameable.isTamed();
if (tameable.getOwner() != null)
_ownerId = tameable.getOwner().getUniqueId();
}
示例9: onPotionSplash
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPotionSplash (PotionSplashEvent event)
{
//ignore potions not thrown by players
ThrownPotion potion = event.getPotion();
ProjectileSource projectileSource = potion.getShooter();
if(projectileSource == null || !(projectileSource instanceof Player)) return;
Player thrower = (Player)projectileSource;
//ignore positive potions
Collection<PotionEffect> effects = potion.getEffects();
boolean hasNegativeEffect = false;
for(PotionEffect effect : effects)
{
if(!EntityEventHandler.positiveEffects.contains(effect.getType()))
{
hasNegativeEffect = true;
break;
}
}
if(!hasNegativeEffect) return;
//if not in a no-pvp world, we don't care
WorldSettings settings = this.settingsManager.Get(potion.getWorld());
if(!settings.pvpRequiresClaimFlag) return;
//ignore potions not effecting players or pets
boolean hasProtectableTarget = false;
for(LivingEntity effected : event.getAffectedEntities())
{
if(effected instanceof Player && effected != thrower)
{
hasProtectableTarget = true;
break;
}
else if(effected instanceof Tameable)
{
Tameable pet = (Tameable)effected;
if(pet.isTamed() && pet.getOwner() != null)
{
hasProtectableTarget = true;
break;
}
}
}
if(!hasProtectableTarget) return;
//if in a flagged-for-pvp area, allow
Flag flag = this.GetFlagInstanceAtLocation(thrower.getLocation(), thrower);
if(flag != null) return;
//otherwise disallow
event.setCancelled(true);
GPFlags.sendMessage(thrower, TextMode.Err, settings.pvpDeniedMessage);
}
示例10: storeTameable
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
public void storeTameable(final Tameable tamed) {
this.tamed = new TameableStats();
this.tamed.owner = tamed.getOwner();
this.tamed.tamed = tamed.isTamed();
}
示例11: getTarget
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
/**
* Gets the closest LivingEntity in player's crosshair
* @return target
*/
public LivingEntity getTarget() {
Location observerPos = this.player.getEyeLocation();
Vector3D observerDir = new Vector3D(observerPos.getDirection());
Vector3D observerStart = new Vector3D(observerPos);
Vector3D observerEnd = observerStart.add(observerDir.multiply(ATTACK_RANGE));
Entity targetEntity = null;
// Loop through nearby entities (may be slow if too many around)
for (Entity entity : this.player.getNearbyEntities(ATTACK_RANGE, ATTACK_RANGE, ATTACK_RANGE)) {
// Skip not living entities
if (!(entity instanceof LivingEntity)) {
continue;
}
// Skip our own wolves
if (entity instanceof Tameable && entity instanceof Wolf) {
Tameable t = (Tameable) entity;
if (t.isTamed() && t.getOwner() == this.player) {
continue;
}
}
// We can't attack what we can't see
if (!this.player.hasLineOfSight(entity)) {
continue;
}
// Bukkit API does not export an axis-aligned bounding box, so we'll settle for this
// Bounding box is set to 1 block in width and 1.67 blocks high from entity's center
Vector3D targetPos = new Vector3D(entity.getLocation());
Vector3D minimum = targetPos.add(-0.5, 0, -0.5);
Vector3D maximum = targetPos.add(0.5, 1.67, 0.5);
if (entity != this.player && Vector3D.hasIntersection(observerStart, observerEnd, minimum, maximum)) {
// Get closest living entity on vector
if (targetEntity == null ||
targetEntity.getLocation().distanceSquared(observerPos) > entity.getLocation().distanceSquared(observerPos)) {
targetEntity = entity;
}
}
}
return (LivingEntity) targetEntity;
}
示例12: storeTameable
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
public void storeTameable(Tameable tamed) {
this.tamed = new TameableStats();
this.tamed.owner = tamed.getOwner();
this.tamed.tamed = tamed.isTamed();
}
示例13: canPreventDamage
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
public static boolean canPreventDamage(Tameable pet, AnimalTamer owner) {
return pet.isTamed() && owner instanceof Player && pet instanceof Wolf;
}
示例14: onEntityTame
import org.bukkit.entity.Tameable; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityTame(EntityTameEvent event)
{
AnimalTamer owner = event.getOwner();
if (owner instanceof Player)
{
Player player = (Player) owner;
if (! plugin.isDisabledWorld(player))
{
// XP Gain
String mobname = FormatUtil.getFriendlyName(event.getEntity().getType());
String article = FormatUtil.getArticle(mobname);
String message = plugin.getPrefix() +
FormatUtil.format(plugin.getMessage("taming_gain"), xpGain, article, mobname);
plugin.getExperienceHandler().handleXpGain(player, xpGain, message);
// Wolf/Ocelot's Pal
PlayerData data = plugin.getPlayerDataCache().getData(player);
int level = data.getLevel(50);
if (Util.random(150 / level) == 0)
{
if (event.getEntity() instanceof Wolf)
{
Wolf wolf = (Wolf) player.getLocation().getWorld().spawnEntity(player.getLocation(), EntityType.WOLF);
wolf.setOwner(player);
}
else if (event.getEntity() instanceof Ocelot)
{
Ocelot ocelot = (Ocelot) player.getLocation().getWorld().spawnEntity(player.getLocation(), EntityType.OCELOT);
ocelot.setOwner(player);
}
}
// Taming Bomb!
if (Util.random(150 / level) == 0)
{
boolean sendMessage = false;
List<Entity> entities = player.getNearbyEntities(10, 10, 10);
if (entities.size() > 0)
{
for (Entity entity : entities)
{
if (entity != null && entity instanceof Tameable)
{
Tameable tameable = (Tameable) entity;
if (! tameable.isTamed())
{
tameable.setOwner(player);
sendMessage = true;
}
}
}
}
if (sendMessage)
{
player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("tame_bomb")));
}
}
}
}
}