Search in sources :

Example 1 with Minecart

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;
}
Also used : MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) Minecart(org.bukkit.entity.Minecart) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 2 with Minecart

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;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) Minecart(org.bukkit.entity.Minecart) Method(java.lang.reflect.Method)

Example 3 with Minecart

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);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Minecart(org.bukkit.entity.Minecart) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Minecart

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);
                }
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Creeper(org.bukkit.entity.Creeper) Minecart(org.bukkit.entity.Minecart) EnderCrystal(org.bukkit.entity.EnderCrystal) Projectile(org.bukkit.entity.Projectile) Golem(org.bukkit.entity.Golem) Animals(org.bukkit.entity.Animals) ArmorStand(org.bukkit.entity.ArmorStand) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Minecart

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);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) MyPetBukkitEntity(de.Keyle.MyPet.api.entity.MyPetBukkitEntity) Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Minecart(org.bukkit.entity.Minecart) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) MyPetBukkitEntity(de.Keyle.MyPet.api.entity.MyPetBukkitEntity) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Minecart (org.bukkit.entity.Minecart)8 Location (org.bukkit.Location)6 Boat (org.bukkit.entity.Boat)5 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 Entity (org.bukkit.entity.Entity)4 LivingEntity (org.bukkit.entity.LivingEntity)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 Hanging (org.bukkit.entity.Hanging)3 Projectile (org.bukkit.entity.Projectile)3 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)2 PvPlayer (me.NoChance.PvPManager.PvPlayer)2 ComplexLivingEntity (org.bukkit.entity.ComplexLivingEntity)2 EnderCrystal (org.bukkit.entity.EnderCrystal)2 ItemFrame (org.bukkit.entity.ItemFrame)2 Painting (org.bukkit.entity.Painting)2 Vehicle (org.bukkit.entity.Vehicle)2 Vector (org.bukkit.util.Vector)2 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)1 BukkitMCAgeable (com.laytonsmith.abstraction.bukkit.entities.BukkitMCAgeable)1