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);
}
use of org.bukkit.entity.Tameable in project MagicPlugin by elBukkit.
the class LevitateSpell method onActivate.
@Override
public void onActivate() {
final Player player = mage.getPlayer();
if (player == null)
return;
// Prevent the player from death by fall
direction = null;
mountBoostTicksRemaining = 0;
boostTicksRemaining = 0;
controller.addFlightExemption(player);
if (stashItem) {
final PlayerInventory inventory = player.getInventory();
heldItem = inventory.getItem(heldItemSlot);
Plugin plugin = controller.getPlugin();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
com.elmakers.mine.bukkit.api.wand.Wand wand = mage.getActiveWand();
if (wand != null) {
wand.deactivate();
}
heldItem = inventory.getItem(heldItemSlot);
inventory.setItem(heldItemSlot, null);
}
}, 1);
} else {
heldItem = null;
}
if (flySpeed > 0) {
player.setFlySpeed(flySpeed * defaultFlySpeed);
}
if (thrustSpeed > 0) {
if (thrust != null) {
thrust.stop();
}
thrust = new ThrustAction(this, thrustFrequency + flyDelay + startDelay, thrustFrequency);
} else if (deactivateFrequency > 0) {
thrust = new ThrustAction(this, deactivateFrequency + flyDelay + startDelay, deactivateFrequency);
}
if (mountType != null) {
Location location = mage.getLocation();
World world = location.getWorld();
Entity entity = null;
try {
String mountName = DeprecatedUtils.getName(mountType);
if (mountName.indexOf("Entity") != 0) {
// TODO: Look into spawning the entity via API calls.
// I think the only reason we jump through all of these hoops is to be able to modify the entity before
// spawning, such as making it invisible. There must be a better way.
mountName = mountName.substring(0, 1).toUpperCase() + mountName.substring(1);
mountName = "Entity" + mountName;
}
Class<?> mountClass = NMSUtils.getBukkitClass("net.minecraft.server." + mountName);
if (mountClass != null) {
if (worldClass == null) {
worldClass = NMSUtils.getBukkitClass("net.minecraft.server.World");
}
Constructor<? extends Object> constructor = mountClass.getConstructor(worldClass);
Object nmsWorld = NMSUtils.getHandle(world);
Object nmsEntity = constructor.newInstance(nmsWorld);
entity = NMSUtils.getBukkitEntity(nmsEntity);
if (entity != null) {
if (entity instanceof LivingEntity && mountInvisible) {
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2 << 24, 0));
}
if (entity instanceof Tameable) {
((Tameable) entity).setTamed(true);
}
if (mountSilent) {
CompatibilityUtils.setSilent(entity, true);
}
Method setLocationMethod = mountClass.getMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE);
setLocationMethod.invoke(nmsEntity, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
controller.setForceSpawn(true);
try {
CompatibilityUtils.addToWorld(world, entity, mountSpawnReason);
} catch (Exception ex) {
ex.printStackTrace();
;
}
controller.setForceSpawn(false);
} else {
mage.sendMessage("Failed to spawn entity of type: " + mountType + " (" + DeprecatedUtils.getName(mountType) + ")");
return;
}
} else {
mage.sendMessage("Invalid entity type: " + mountType + " (" + DeprecatedUtils.getName(mountType) + ")");
return;
}
} catch (Exception ex) {
ex.printStackTrace();
}
if (entity != null) {
mountEntity = entity;
CompatibilityUtils.setInvulnerable(mountEntity);
if (entity instanceof Horse) {
Horse horse = (Horse) mountEntity;
horse.setTamed(true);
horse.setOwner(player);
horse.setAdult();
horse.setStyle(mountHorseStyle);
// horse.setVariant(mountHorseVariant);
horse.setColor(mountHorseColor);
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE, 1));
if (mountItem != null) {
horse.getInventory().setArmor(new ItemStack(mountItem, 1));
}
if (mountBaby) {
horse.setBaby();
}
}
if (entity instanceof Pig) {
Pig pig = (Pig) entity;
pig.setSaddle(true);
if (mountBaby) {
pig.setBaby();
}
}
if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity) mountEntity;
living.setHealth(0.5);
living.setMaxHealth(mountHealth);
}
if (entity instanceof ArmorStand) {
ArmorStand armorStand = (ArmorStand) entity;
configureArmorStand(armorStand);
} else if (useArmorStand) {
armorStand = CompatibilityUtils.createArmorStand(mage.getLocation());
configureArmorStand(armorStand);
armorStand.setPassenger(mountEntity);
armorStand.setMetadata("notarget", new FixedMetadataValue(controller.getPlugin(), true));
armorStand.setMetadata("broom", new FixedMetadataValue(controller.getPlugin(), true));
controller.setForceSpawn(true);
try {
CompatibilityUtils.addToWorld(mage.getLocation().getWorld(), armorStand, mountSpawnReason);
} catch (Exception ex) {
ex.printStackTrace();
}
controller.setForceSpawn(false);
} else {
armorStand = null;
}
mountEntity.setPassenger(mage.getEntity());
mountEntity.setMetadata("notarget", new FixedMetadataValue(controller.getPlugin(), true));
mountEntity.setMetadata("broom", new FixedMetadataValue(controller.getPlugin(), true));
if (listener == null) {
listener = new LevitateListener(controller);
Plugin plugin = controller.getPlugin();
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
}
}
}
grounded = false;
if (maxHeight > 0 && player.getLocation().getY() >= maxHeight) {
grounded = true;
} else if (maxHeightAboveGround > 0) {
Block block = player.getLocation().getBlock();
int height = 0;
while (height < maxHeightAboveGround && block.getType() == Material.AIR) {
block = block.getRelative(BlockFace.DOWN);
height++;
}
if (block.getType() == Material.AIR) {
grounded = true;
}
}
if (!grounded) {
Vector velocity = player.getVelocity();
velocity.setY(velocity.getY() + yBoost);
if (mountEntity != null) {
if (armorStand != null) {
SafetyUtils.setVelocity(armorStand, velocity);
} else {
SafetyUtils.setVelocity(mountEntity, velocity);
}
} else {
SafetyUtils.setVelocity(player, velocity);
}
}
if (flight) {
Bukkit.getScheduler().scheduleSyncDelayedTask(controller.getPlugin(), new Runnable() {
@Override
public void run() {
player.setAllowFlight(true);
player.setFlying(true);
}
}, flyDelay);
}
}
Aggregations