Search in sources :

Example 11 with Vehicle

use of org.bukkit.entity.Vehicle in project RedProtect by FabioZumbi12.

the class RPBlockListener method onVehicleBreak.

@EventHandler
public void onVehicleBreak(VehicleDestroyEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is VehicleDestroyEvent event");
    if (e.isCancelled()) {
        return;
    }
    if (!(e.getAttacker() instanceof Player)) {
        return;
    }
    Vehicle cart = e.getVehicle();
    Player p = (Player) e.getAttacker();
    Region r = RedProtect.get().rm.getTopRegion(cart.getLocation());
    if (r != null && !r.canMinecart(p)) {
        RPLang.sendMessage(p, "blocklistener.region.cantbreak");
        e.setCancelled(true);
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Player(org.bukkit.entity.Player) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 12 with Vehicle

use of org.bukkit.entity.Vehicle 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);
}
Also used : BukkitMCTameable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCTameable) BukkitMCHumanEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) BukkitMCComplexEntityPart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexEntityPart) BukkitMCTameable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCTameable) Tameable(org.bukkit.entity.Tameable) BukkitMCAgeable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCAgeable) BukkitMCEntityType(com.laytonsmith.abstraction.enums.bukkit.BukkitMCEntityType) BukkitMCCommandMinecart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCCommandMinecart) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart) Minecart(org.bukkit.entity.Minecart) BukkitMCMinecart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCMinecart) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) BukkitMCHanging(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHanging) Ageable(org.bukkit.entity.Ageable) BukkitMCAgeable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCAgeable) BukkitMCLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity) BukkitMCProjectile(com.laytonsmith.abstraction.bukkit.entities.BukkitMCProjectile) Projectile(org.bukkit.entity.Projectile) BukkitMCProjectile(com.laytonsmith.abstraction.bukkit.entities.BukkitMCProjectile) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) BukkitMCLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Vehicle(org.bukkit.entity.Vehicle) BukkitMCVehicle(com.laytonsmith.abstraction.bukkit.entities.BukkitMCVehicle) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) BukkitMCMinecart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCMinecart) Hanging(org.bukkit.entity.Hanging) BukkitMCHanging(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHanging) BukkitMCHumanEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) BukkitMCComplexEntityPart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexEntityPart) BukkitMCVehicle(com.laytonsmith.abstraction.bukkit.entities.BukkitMCVehicle)

Example 13 with Vehicle

use of org.bukkit.entity.Vehicle in project askyblock by tastybento.

the class SafeBoat method onClick.

/**
 * @param e - event
 *            This event check throws the boat at a player when they hit it
 *            unless someone is in it
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onClick(VehicleDamageEvent e) {
    // plugin.getLogger().info("Damage event " + e.getDamage());
    // Find out what block is being clicked
    Vehicle boat = e.getVehicle();
    if (!(boat instanceof Boat)) {
        return;
    }
    if (!boat.isEmpty()) {
        return;
    }
    final World playerWorld = boat.getWorld();
    if (!playerWorld.getName().equalsIgnoreCase(Settings.worldName)) {
        // Not the right world
        return;
    }
    // Find out who is doing the clicking
    if (!(e.getAttacker() instanceof Player)) {
        // If a creeper blows up the boat, tough cookies!
        return;
    }
    Player p = (Player) e.getAttacker();
    if (p == null) {
        return;
    }
    // Try to remove the boat and throw it at the player
    Location boatSpot = new Location(boat.getWorld(), boat.getLocation().getX(), boat.getLocation().getY() + 2, boat.getLocation().getZ());
    Location throwTo = new Location(boat.getWorld(), p.getLocation().getX(), p.getLocation().getY() + 1, p.getLocation().getZ());
    ItemStack newBoat = new ItemStack(Material.BOAT, 1);
    // Find the direction the boat should move in
    Vector dir = throwTo.toVector().subtract(boatSpot.toVector()).normalize();
    dir = dir.multiply(0.5);
    Entity newB = boat.getWorld().dropItem(boatSpot, newBoat);
    newB.setVelocity(dir);
    boat.remove();
    e.setCancelled(true);
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) World(org.bukkit.World) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Boat(org.bukkit.entity.Boat) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 14 with Vehicle

use of org.bukkit.entity.Vehicle in project Statz by Staartvin.

the class DistanceTravelledVehicleListener method onMove.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(final VehicleMoveEvent event) {
    final PlayerStat stat = PlayerStat.DISTANCE_TRAVELLED;
    Vehicle vehicle = event.getVehicle();
    if (vehicle.getPassenger() == null)
        return;
    // Get player
    final Player player;
    String movementType;
    if (vehicle.getPassenger() instanceof Player) {
        player = (Player) vehicle.getPassenger();
        movementType = StatzUtil.getMovementType(player);
    } else {
        // No passenger on the passenger
        if (vehicle.getPassenger().getPassenger() == null)
            return;
        // There is no player riding.
        if (!(vehicle.getPassenger().getPassenger() instanceof Player))
            return;
        player = (Player) vehicle.getPassenger().getPassenger();
        movementType = StatzUtil.getMovementType(player);
    }
    // No player found, no movementType found.
    if (player == null || movementType == null)
        return;
    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;
    final double distTravelled = event.getFrom().distance(event.getTo());
    if (distTravelled == 0) {
        return;
    }
    final String movement = movementType;
    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", distTravelled, "moveType", movement, "world", player.getWorld().getName()));
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 15 with Vehicle

use of org.bukkit.entity.Vehicle in project Prism-Bukkit by prism.

the class PrismVehicleEvents method onVehicleCreate.

/**
 * VehicleCreateEvent.
 *
 * @param event VehicleCreateEvent
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleCreate(final VehicleCreateEvent event) {
    final Vehicle vehicle = event.getVehicle();
    final Location loc = vehicle.getLocation();
    final String coord_key = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
    String value = plugin.preplannedVehiclePlacement.get(coord_key);
    UUID uuid = null;
    try {
        uuid = UUID.fromString(value);
    } catch (Exception ignored) {
    // ignored.
    }
    final OfflinePlayer player = uuid != null ? Bukkit.getOfflinePlayer(uuid) : null;
    if (player != null) {
        // TODO: name ref
        if (!Prism.getIgnore().event("vehicle-place", loc.getWorld(), player.getName())) {
            return;
        }
        RecordingQueue.addToQueue(ActionFactory.createVehicle("vehicle-place", vehicle, player));
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Vehicle (org.bukkit.entity.Vehicle)21 EventHandler (org.bukkit.event.EventHandler)12 Player (org.bukkit.entity.Player)9 Location (org.bukkit.Location)6 Entity (org.bukkit.entity.Entity)6 Vector (org.bukkit.util.Vector)3 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 Team (au.com.mineauz.minigames.minigame.Team)2 DynamicMinigameStat (au.com.mineauz.minigames.stats.DynamicMinigameStat)2 StoredGameStats (au.com.mineauz.minigames.stats.StoredGameStats)2 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)2 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 BlockData (com.bergerkiller.bukkit.common.wrappers.BlockData)2 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)2 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)2 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)2 Random (java.util.Random)2 Boat (org.bukkit.entity.Boat)2 LivingEntity (org.bukkit.entity.LivingEntity)2 VehicleExitEvent (org.bukkit.event.vehicle.VehicleExitEvent)2