Java Code Examples for org.bukkit.event.vehicle.VehicleDestroyEvent#getAttacker()

The following examples show how to use org.bukkit.event.vehicle.VehicleDestroyEvent#getAttacker() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler
public void minecartBreak(VehicleDestroyEvent e) {
    Entity entity = e.getVehicle();
    if (plugin.getLWC().isProtectable(e.getVehicle().getType())) {
        int A = 50000 + entity.getUniqueId().hashCode();
        LWC lwc = LWC.getInstance();
        Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A);
        if ((((entity instanceof StorageMinecart)) || ((entity instanceof HopperMinecart)))
                && (protection != null)) {
            if (e.getAttacker() instanceof Projectile) {
                e.setCancelled(true);
            }
            Player p = (Player) e.getAttacker();
            boolean canAccess = lwc.canAccessProtection(p, protection);
            if (canAccess) {
                protection.remove();
                protection.removeAllPermissions();
                protection.removeCache();
                return;
            }
            e.setCancelled(true);
        }
    }
}
 
Example 2
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onVehicleBreak(VehicleDestroyEvent e) {
    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) {
        return;
    }

    if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.bypass.world")) {
        e.setCancelled(true);
    }
}
 
Example 3
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onVehicleBreak(VehicleDestroyEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is VehicleDestroyEvent event");

    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)) {
        RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak");
        e.setCancelled(true);
    }
}
 
Example 4
Source File: SafeBoat.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param e - event
 *            This function prevents boats from exploding when they hit
 *            something
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void onBoatHit(VehicleDestroyEvent e) {
    // plugin.getLogger().info("Vehicle destroyed event called");
    final Entity boat = e.getVehicle();
    if (!(boat instanceof Boat)) {
        return;
    }
    if (!boat.getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
        // Not the right world
        return;
    }
    if (!(e.getAttacker() instanceof Player)) {
        // plugin.getLogger().info("Attacker is not a player so cancel event");
        e.setCancelled(true);
    }
}
 
Example 5
Source File: EntityEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onVehicleDestroy(VehicleDestroyEvent event) {
    GDTimings.ENTITY_DAMAGE_EVENT.startTiming();
    final Object source = event.getAttacker() != null ? event.getAttacker() : NMSUtil.getInstance().getBlockDamager();
    if (protectEntity(event, source, (Entity) event.getVehicle())) {
        event.setCancelled(true);
    }
    GDTimings.ENTITY_DAMAGE_EVENT.stopTiming();
}
 
Example 6
Source File: ExploitEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void on(VehicleDestroyEvent e) {
    if (breakVehicleEnabled
            || !(e.getAttacker() instanceof Player)
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getVehicle().getWorld())
    ) {
        return;
    }
    Player player = (Player) e.getAttacker();
    if (player.hasPermission("usb.mod.bypassprotection") || plugin.playerIsOnIsland(player)) {
        return;
    }
    e.setCancelled(true);
    player.sendMessage(tr("\u00a7eYou cannot break vehicles while being a visitor!"));
}