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 solinia3-core by mixxit.
the class CommandSolNPCInfo method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("This is a player only command");
return true;
}
// sender.sendMessage("Fetching information about NPC targetted");
Player player = (Player) sender;
try {
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
LivingEntity targetmob = solPlayer.getEntityTarget();
if (targetmob == null) {
player.sendMessage("You need to target an NPC for info about it");
return true;
}
ISoliniaLivingEntity solLivingEntity = SoliniaLivingEntityAdapter.Adapt(targetmob);
String mobtag = "";
String npcidtag = "";
player.sendMessage("EQUIPMENT");
for (ISoliniaItem solItem : solLivingEntity.getEquippedSoliniaItems()) {
player.sendMessage("SolItemId: " + solItem.getId() + " " + solItem.getDisplayname());
}
if (solLivingEntity.getBukkitLivingEntity().hasMetadata("Faction")) {
String metadata = "";
for (MetadataValue val : solLivingEntity.getBukkitLivingEntity().getMetadata("Faction")) {
metadata = val.asString();
}
player.sendMessage("Faction: " + metadata);
}
player.sendMessage("Active Effects");
try {
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(solLivingEntity.getBukkitLivingEntity()).getActiveSpells()) {
player.sendMessage(spell.getSpell().getName());
for (ActiveSpellEffect effect : spell.getActiveSpellEffects()) {
player.sendMessage(" - " + effect.getSpellEffectType().name() + " " + effect.getRemainingValue());
}
}
} catch (CoreStateInitException e) {
//
}
solLivingEntity.sendHateList(player);
solLivingEntity.sendStats(player);
for (MetadataValue val : targetmob.getMetadata("mobname")) mobtag = "mobname tag: " + ChatColor.GOLD + val.asString() + ChatColor.RESET;
for (MetadataValue val : targetmob.getMetadata("npcid")) npcidtag = "npcid tag: " + ChatColor.GOLD + val.asString() + ChatColor.RESET;
// player.sendMessage("GUID: " + targetmob.getUniqueId() + " IsNPC: " + solLivingEntity.isNPC() + " npcid: " + npcid);
player.sendMessage(mobtag + " " + npcidtag);
if (solLivingEntity.getBukkitLivingEntity() instanceof Creature) {
String parent = "Owner: " + ChatColor.GOLD + solLivingEntity.getActiveMob().getOwner() + ChatColor.RESET;
String owner = "Parent: " + ChatColor.GOLD + solLivingEntity.getActiveMob().getParent() + ChatColor.RESET;
String tame = "";
if (solLivingEntity.getBukkitLivingEntity() instanceof Tameable)
tame = "TameOwner: " + ChatColor.GOLD + ((Tameable) (solLivingEntity.getBukkitLivingEntity())).getOwner() + ChatColor.RESET;
player.sendMessage(parent + " " + owner + " " + tame);
}
String canSee = "";
if (player.isOp())
canSee = "Can i see you: " + ChatColor.GOLD + solLivingEntity.checkLosFN(SoliniaLivingEntityAdapter.Adapt(player));
String attackTarget = "Minecraft attack target: " + ChatColor.GOLD + (solLivingEntity.getAttackTarget() == null ? "None" : solLivingEntity.getAttackTarget().getName()) + ChatColor.RESET + " " + canSee;
if (solLivingEntity.getSpawnPoint() == null) {
player.sendMessage("spawnpoint: " + ChatColor.GOLD + "null");
} else {
player.sendMessage("spawnpoint: " + ChatColor.GOLD + solLivingEntity.getSpawnPoint().getWorld().getName() + "," + solLivingEntity.getSpawnPoint().getX() + "," + solLivingEntity.getSpawnPoint().getY() + "," + solLivingEntity.getSpawnPoint().getZ());
}
if (player.isOp() && solLivingEntity.isNPC()) {
ISoliniaNPC npc = solLivingEntity.getNPC();
double hp = solLivingEntity.getStatMaxHP(75);
if (npc.isHeroic()) {
hp += (NPCUtils.getHeroicHPMultiplier() * npc.getLevel());
}
if (npc.isBoss()) {
hp += (NPCUtils.getBossHPMultiplier(npc.isHeroic()) * npc.getLevel());
}
if (npc.isRaidheroic()) {
hp += (NPCUtils.getRaidHeroicHPMultiplier() * npc.getLevel());
}
if (npc.isRaidboss()) {
hp += (NPCUtils.getRaidBossHPMultiplier() * npc.getLevel());
}
if (npc.getForcedMaxHp() > 0)
hp = npc.getForcedMaxHp();
double damage = npc.getMaxDamage();
player.sendMessage("Debug calc hp: " + hp + " " + "Debug calc dmg: " + npc.getMaxDamage());
}
player.sendMessage(attackTarget);
if (player.isOp())
player.sendMessage("isCollidable: " + targetmob.isCollidable());
} catch (CoreStateInitException e) {
player.sendMessage("SoliniaNPCInfo: " + "Could not fetch information");
}
return true;
}
use of org.bukkit.entity.Tameable in project Essentials by EssentialsX.
the class Commandremove method removeHandler.
private void removeHandler(final CommandSource sender, final List<String> types, final List<String> customTypes, final World world, int radius) {
int removed = 0;
if (radius > 0) {
radius *= radius;
}
final ArrayList<ToRemove> removeTypes = new ArrayList<>();
final ArrayList<Mob> customRemoveTypes = new ArrayList<>();
for (final String s : types) {
removeTypes.add(ToRemove.valueOf(s));
}
boolean warnUser = false;
for (final String s : customTypes) {
final Mob mobType = Mob.fromName(s);
if (mobType == null) {
warnUser = true;
} else {
customRemoveTypes.add(mobType);
}
}
if (warnUser) {
sender.sendMessage(tl("invalidMob"));
}
for (final Chunk chunk : world.getLoadedChunks()) {
for (final Entity e : chunk.getEntities()) {
if (radius > 0) {
if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
continue;
}
}
if (e instanceof HumanEntity) {
continue;
}
for (final ToRemove toRemove : removeTypes) {
// We should skip any animals tamed by players unless we are specifially targetting them.
if (e instanceof Tameable && ((Tameable) e).isTamed() && (((Tameable) e).getOwner() instanceof Player || ((Tameable) e).getOwner() instanceof OfflinePlayer) && !removeTypes.contains(ToRemove.TAMED)) {
continue;
}
// We should skip any NAMED animals unless we are specifially targetting them.
if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
continue;
}
switch(toRemove) {
case TAMED:
if (e instanceof Tameable && ((Tameable) e).isTamed()) {
e.remove();
removed++;
}
break;
case NAMED:
if (e instanceof LivingEntity && e.getCustomName() != null) {
e.remove();
removed++;
}
break;
case DROPS:
if (e instanceof Item) {
e.remove();
removed++;
}
break;
case ARROWS:
if (e instanceof Projectile) {
e.remove();
removed++;
}
break;
case BOATS:
if (e instanceof Boat) {
e.remove();
removed++;
}
break;
case MINECARTS:
if (e instanceof Minecart) {
e.remove();
removed++;
}
break;
case XP:
if (e instanceof ExperienceOrb) {
e.remove();
removed++;
}
break;
case PAINTINGS:
if (e instanceof Painting) {
e.remove();
removed++;
}
break;
case ITEMFRAMES:
if (e instanceof ItemFrame) {
e.remove();
removed++;
}
break;
case ENDERCRYSTALS:
if (e instanceof EnderCrystal) {
e.remove();
removed++;
}
break;
case AMBIENT:
if (e instanceof Flying) {
e.remove();
removed++;
}
break;
case HOSTILE:
case MONSTERS:
if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
e.remove();
removed++;
}
break;
case PASSIVE:
case ANIMALS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case MOBS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case ENTITIES:
case ALL:
e.remove();
removed++;
break;
case CUSTOM:
for (final Mob type : customRemoveTypes) {
if (e.getType() == type.getType()) {
e.remove();
removed++;
}
}
break;
}
}
}
}
sender.sendMessage(tl("removed", removed));
}
use of org.bukkit.entity.Tameable in project MagicPlugin by elBukkit.
the class CompatibilityUtilsBase method getOwnerId.
@Override
public UUID getOwnerId(Entity entity) {
String ownerIdString = platform.getEnityMetadataUtils().getString(entity, MagicMetaKeys.OWNER);
if (ownerIdString != null && !ownerIdString.isEmpty()) {
try {
return UUID.fromString(ownerIdString);
} catch (Exception ex) {
platform.getLogger().warning("Error parsing owner id from: " + ownerIdString);
}
}
if (entity instanceof Tameable) {
Tameable tamed = (Tameable) entity;
AnimalTamer tamer = tamed.getOwner();
return tamer == null ? null : tamer.getUniqueId();
}
return null;
}
use of org.bukkit.entity.Tameable in project MagicPlugin by elBukkit.
the class CompatibilityUtilsBase method tame.
@Override
public boolean tame(Entity entity, Player tamer) {
if (!(entity instanceof Tameable)) {
return false;
}
Tameable tameable = (Tameable) entity;
if (tameable.isTamed()) {
return false;
}
tameable.setTamed(true);
if (tamer != null) {
tameable.setOwner(tamer);
}
return true;
}
Aggregations