use of org.bukkit.entity.Tameable in project proskillapi by promcteam.
the class CombatProtection method canAttack.
static boolean canAttack(LivingEntity attacker, LivingEntity target, boolean passiveAlly) {
if (attacker == target) {
return false;
} else {
if (target instanceof Tameable) {
Tameable entity = (Tameable) target;
if (entity.isTamed() && entity.getOwner() instanceof OfflinePlayer) {
OfflinePlayer owner = (OfflinePlayer) entity.getOwner();
if (owner.isOnline()) {
return canAttack(attacker, owner.getPlayer(), false);
}
}
} else if (passiveAlly && target instanceof Animals) {
return false;
}
DefaultCombatProtection.FakeEntityDamageByEntityEvent event = new DefaultCombatProtection.FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.CUSTOM, 1.0D);
Bukkit.getPluginManager().callEvent(event);
boolean attackable = !event.isExternallyCancelled();
event.setCancelled(true);
return attackable;
}
}
use of org.bukkit.entity.Tameable in project MyPet by xXKeyleXx.
the class GriefPreventionPlusHook method canHurt.
@Override
public boolean canHurt(Player attacker, Entity defender) {
try {
if (!griefPrevention.claimsEnabledForWorld(defender.getWorld())) {
return true;
}
DataStore dataStore = griefPrevention.getDataStore();
if (!(defender instanceof Monster) && griefPrevention.config.claims_protectCreatures) {
if (defender instanceof Tameable && !griefPrevention.config.pvp_enabledWorlds.contains(defender.getWorld().getUID())) {
final Tameable tameable = (Tameable) defender;
if (tameable.isTamed() && (tameable.getOwner() != null)) {
final UUID ownerID = tameable.getOwner().getUniqueId();
if (attacker.getUniqueId().equals(ownerID)) {
return false;
}
final PlayerData attackerData = dataStore.getPlayerData(attacker.getUniqueId());
if (attackerData.ignoreClaims) {
return true;
}
}
}
PlayerData playerData = dataStore.getPlayerData(attacker.getUniqueId());
Claim claim = dataStore.getClaimAt(defender.getLocation(), false, playerData.lastClaim);
if (claim != null) {
if (claim.canOpenContainers(attacker) != null) {
return false;
}
}
}
} catch (Throwable ignored) {
}
return true;
}
use of org.bukkit.entity.Tameable in project Prism-Bukkit by prism.
the class EntitySerializer method serialize.
/**
* Serialize entity.
* @param entity Entity.
*/
public final void serialize(Entity entity) {
entityName = entity.getType().name().toLowerCase();
// Get custom name
customName = entity.getCustomName();
// Get animal age
if (entity instanceof Ageable) {
isAdult = ((Ageable) entity).isAdult();
}
// Owner
if (entity instanceof Tameable) {
final Tameable mob = (Tameable) entity;
if (mob.getOwner() != null) {
tamingOwner = mob.getOwner().getUniqueId().toString();
} else if (mob.isTamed()) {
tamingOwner = "-none-";
}
}
// Sitting
if (entity instanceof Sittable) {
sitting = ((Sittable) entity).isSitting();
}
EntityDamageEvent damageEvent = entity.getLastDamageCause();
// Saves us the null check
if (damageEvent instanceof EntityDamageByEntityEvent && !damageEvent.isCancelled() && damageEvent.getDamage() > ((LivingEntity) entity).getHealth()) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) damageEvent;
if (e.getDamager() instanceof Projectile) {
customDesc = EntityUtils.getCustomProjectileDescription((Projectile) e.getDamager());
}
}
serializer(entity);
}
use of org.bukkit.entity.Tameable in project Jobs by GamingMesh.
the class JobsPaymentListener method onEntityDeath.
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
// Entity that died must be living
if (!(event.getEntity() instanceof LivingEntity))
return;
LivingEntity lVictim = (LivingEntity) event.getEntity();
// mob spawner, no payment or experience
if (lVictim.hasMetadata(mobSpawnerMetadata)) {
lVictim.removeMetadata(mobSpawnerMetadata, plugin);
return;
}
// make sure plugin is enabled
if (!plugin.isEnabled())
return;
if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
org.bukkit.entity.Player pDamager = null;
if (e.getDamager() instanceof org.bukkit.entity.Player) {
pDamager = (org.bukkit.entity.Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof org.bukkit.entity.Player) {
pDamager = (org.bukkit.entity.Player) ((Projectile) e.getDamager()).getShooter();
} else if (e.getDamager() instanceof Tameable) {
Tameable t = (Tameable) e.getDamager();
if (t.isTamed() && t.getOwner() instanceof org.bukkit.entity.Player) {
pDamager = (org.bukkit.entity.Player) t.getOwner();
}
}
if (pDamager != null) {
// check if in creative
if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
return;
// restricted area multiplier
double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(pDamager);
// pay
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
Jobs.action(jDamager, new EntityActionInfo(lVictim.getType(), ActionType.KILL), multiplier);
}
}
}
use of org.bukkit.entity.Tameable in project CommandHelper by EngineHub.
the class BukkitConvertor method BukkitGetCorrectEntity.
// /**
// * We don't want to allow scripts to clear other plugin's tasks
// * on accident, so only ids registered through our interface
// * can also be cancelled.
// */
// private static final Set<Integer> validIDs = new TreeSet<Integer>();
//
// @Override
// public synchronized int SetFutureRunnable(DaemonManager dm, long ms, Runnable r) {
// int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CommandHelperPlugin.self, r, Static.msToTicks(ms));
// validIDs.add(id);
// return id;
// }
//
// @Override
// public synchronized int SetFutureRepeater(DaemonManager dm, long ms, long initialDelay, Runnable r){
// int id = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CommandHelperPlugin.self, r, Static.msToTicks(initialDelay), Static.msToTicks(ms));
// validIDs.add(id);
// return id;
// }
//
// @Override
// public synchronized void ClearAllRunnables() {
// //Doing cancelTasks apparently does not work, so let's just manually cancel each task, which does appear to work.
// //Anyways, it's better that way anyhow, because we actually remove IDs from validIDs that way.
// //((BukkitMCServer)Static.getServer()).__Server().getScheduler().cancelTasks(CommandHelperPlugin.self);
// Set<Integer> ids = new TreeSet<Integer>(validIDs);
// for(int id : ids){
// try{
// //If this doesn't work, it shouldn't kill everything.
// ClearFutureRunnable(id);
// } catch(Exception e){
// Logger.getLogger(BukkitConvertor.class.getName()).log(null, Level.SEVERE, e);
// }
// }
// }
//
// @Override
// public void ClearFutureRunnable(int id) {
// if(validIDs.contains(id)){
// Bukkit.getServer().getScheduler().cancelTask(id);
// validIDs.remove(id);
// }
// }
public static MCEntity BukkitGetCorrectEntity(Entity be) {
if (be == null) {
return null;
}
BukkitMCEntityType type = BukkitMCEntityType.valueOfConcrete(be.getType());
if (type.getWrapperClass() != null) {
return ReflectionUtils.newInstance(type.getWrapperClass(), new Class[] { Entity.class }, new Object[] { be });
}
if (be instanceof Hanging) {
type.setWrapperClass(BukkitMCHanging.class);
return new BukkitMCHanging(be);
}
if (be instanceof Minecart) {
// Must come before Vehicle
type.setWrapperClass(BukkitMCMinecart.class);
return new BukkitMCMinecart(be);
}
if (be instanceof Projectile) {
type.setWrapperClass(BukkitMCProjectile.class);
return new BukkitMCProjectile(be);
}
if (be instanceof Tameable) {
// Must come before Ageable
type.setWrapperClass(BukkitMCTameable.class);
return new BukkitMCTameable(be);
}
if (be instanceof Ageable) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCAgeable.class);
return new BukkitMCAgeable(be);
}
if (be instanceof HumanEntity) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCHumanEntity.class);
return new BukkitMCHumanEntity(be);
}
if (be instanceof ComplexEntityPart) {
type.setWrapperClass(BukkitMCComplexEntityPart.class);
return new BukkitMCComplexEntityPart(be);
}
if (be instanceof ComplexLivingEntity) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCComplexLivingEntity.class);
return new BukkitMCComplexLivingEntity(be);
}
if (be instanceof LivingEntity) {
type.setWrapperClass(BukkitMCLivingEntity.class);
return new BukkitMCLivingEntity(be);
}
if (be instanceof Vehicle) {
type.setWrapperClass(BukkitMCVehicle.class);
return new BukkitMCVehicle(be);
}
// Handle generically if we can't find a more specific type
type.setWrapperClass(BukkitMCEntity.class);
return new BukkitMCEntity(be);
}
Aggregations