use of org.bukkit.entity.Minecart in project MagicPlugin by elBukkit.
the class ShapeBatch method createBlock.
public boolean createBlock(int dx, int dy, int dz) {
// Special-case hackiness..
if (limitYAxis && minOrientDimension != null && dy < -minOrientDimension)
return true;
if (limitYAxis && maxOrientDimension != null && dy > maxOrientDimension)
return true;
// Initial range checks, we skip everything if this is not sane.
int x = center.getBlockX() + dx;
int y = center.getBlockY() + dy;
int z = center.getBlockZ() + dz;
if (y < 0 || y > center.getWorld().getMaxHeight())
return true;
// Make sure the block is loaded.
Block block = center.getWorld().getBlockAt(x, y, z);
if (!block.getChunk().isLoaded()) {
block.getChunk().load();
return false;
}
// Prepare material brush, it may update
// given the current target (clone, replicate)
MaterialBrush brush = spell.getBrush();
brush.update(mage, block.getLocation());
// Make sure the brush is ready, it may need to load chunks.
if (!brush.isReady()) {
brush.prepare();
return false;
}
if (!spell.hasBuildPermission(block)) {
return true;
}
Location loc = center.clone();
Vector direction = block.getLocation().toVector().subtract(center.toVector()).normalize();
loc.setDirection(direction);
Minecart minecart = CompatibilityUtils.spawnCustomMinecart(loc, brush.getMaterial(), brush.getData(), radius * 16);
registerForUndo(minecart);
return true;
}
use of org.bukkit.entity.Minecart in project MagicPlugin by elBukkit.
the class CompatibilityUtils method spawnCustomMinecart.
public static Minecart spawnCustomMinecart(Location location, Material material, short data, int offset) {
Minecart newMinecart = null;
try {
Constructor<?> minecartConstructor = class_EntityMinecartRideable.getConstructor(class_World, Double.TYPE, Double.TYPE, Double.TYPE);
Method addEntity = class_World.getMethod("addEntity", class_Entity, CreatureSpawnEvent.SpawnReason.class);
Method setPositionRotationMethod = class_Entity.getMethod("setPositionRotation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE);
Object worldHandle = getHandle(location.getWorld());
Object newEntity = minecartConstructor.newInstance(worldHandle, location.getX(), location.getY(), location.getZ());
if (newEntity != null) {
// Set initial rotation
setPositionRotationMethod.invoke(newEntity, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
// Set tile material id, pack into NMS 3-byte format
// TODO: Unbreak this maybe one day?
/*
int materialId = (display.getMaterial().getId() & 0xFFFF) | (display.getData() << 16);
watch(newEntity, 20, materialId);
// Set the tile offset
watch(newEntity, 21, offset);
// Finalize custom display tile
watch(newEntity, 22, (byte)1);
*/
addEntity.invoke(worldHandle, newEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
Entity bukkitEntity = getBukkitEntity(newEntity);
if (bukkitEntity == null || !(bukkitEntity instanceof Minecart))
return null;
newMinecart = (Minecart) bukkitEntity;
}
} catch (Throwable ex) {
ex.printStackTrace();
}
return newMinecart;
}
use of org.bukkit.entity.Minecart in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEntityEvent e) {
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
Entity ent = e.getRightClicked();
Location l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null) {
return;
}
if (ent instanceof ItemFrame || ent instanceof Painting) {
if (!bypassBuild(p, null, 0)) {
e.setCancelled(true);
return;
}
}
if (ent instanceof Minecart || ent instanceof Boat) {
if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".interact") && !p.hasPermission("redprotect.bypass.world") && (!(ent instanceof Player))) {
if (RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-entities").contains(ent.getType().name())) {
return;
}
e.setCancelled(true);
}
}
use of org.bukkit.entity.Minecart in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onEntityDamageEntity.
@EventHandler
public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
if (e.isCancelled()) {
return;
}
Entity e1 = e.getEntity();
Entity e2 = e.getDamager();
Location loc = e1.getLocation();
Region r1 = RedProtect.get().rm.getTopRegion(loc);
if (r1 != null) {
return;
}
if (e2 instanceof Creeper || e2.getType().equals(EntityType.PRIMED_TNT) || e2.getType().equals(EntityType.MINECART_TNT)) {
if (e1 instanceof Player) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
}
if (e2 instanceof Player) {
Player p = (Player) e2;
if (e.getCause().equals(DamageCause.LIGHTNING) || e.getCause().equals(DamageCause.BLOCK_EXPLOSION) || e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".entity-block-damage")) {
e.setCancelled(true);
return;
}
}
if ((e1 instanceof Minecart || e1 instanceof Boat) && !RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
if (e1 instanceof Player) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
e.setCancelled(true);
return;
}
}
}
if (e2 instanceof Projectile) {
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Player) {
Player p = (Player) proj.getShooter();
if (e1 instanceof Player) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
e.setCancelled(true);
}
}
}
}
}
use of org.bukkit.entity.Minecart in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
Entity e = event.getRightClicked();
Player p = event.getPlayer();
if (e == null) {
return;
}
RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEntityEvent event: " + e.getType().name());
Location l = e.getLocation();
if (e instanceof ItemFrame || e instanceof Painting) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
event.setCancelled(true);
}
} else if ((e instanceof Minecart || e instanceof Boat)) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantenter");
event.setCancelled(true);
}
} else if (RedProtect.get().MyPet && e instanceof MyPetBukkitEntity) {
if (((MyPetBukkitEntity) e).getOwner().getPlayer().equals(p)) {
}
} else if (!RPUtil.isBukkitEntity(e) && (!(event.getRightClicked() instanceof Player))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.allowMod(p)) {
RedProtect.get().logger.debug("PlayerInteractEntityEvent - Block is " + event.getRightClicked().getType().name());
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
}
}
Aggregations