Search in sources :

Example 46 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class PaperListener113 method onBlockPlace.

@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
    if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
        return;
    }
    BlockState state = event.getBlock().getState(false);
    if (!(state instanceof Banner || state instanceof Beacon || state instanceof Bed || state instanceof CommandBlock || state instanceof Comparator || state instanceof Conduit || state instanceof Container || state instanceof CreatureSpawner || state instanceof DaylightDetector || state instanceof EnchantingTable || state instanceof EnderChest || state instanceof EndGateway || state instanceof Jukebox || state instanceof Sign || state instanceof Skull || state instanceof Structure)) {
        return;
    }
    final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
    final PlotArea plotArea = location.getPlotArea();
    if (plotArea == null) {
        return;
    }
    final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
    if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
        final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
        plotPlayer.sendMessage(TranslatableCaption.of("errors.tile_entity_cap_reached"), Template.of("amount", String.valueOf(Settings.Chunk_Processor.MAX_TILES)));
        event.setCancelled(true);
        event.setBuild(false);
    }
}
Also used : Bed(org.bukkit.block.data.type.Bed) Jukebox(org.bukkit.block.Jukebox) PlotArea(com.plotsquared.core.plot.PlotArea) Banner(org.bukkit.block.Banner) CommandBlock(org.bukkit.block.CommandBlock) DaylightDetector(org.bukkit.block.DaylightDetector) Comparator(org.bukkit.block.Comparator) CreatureSpawner(org.bukkit.block.CreatureSpawner) Container(org.bukkit.block.Container) EndGateway(org.bukkit.block.EndGateway) BlockState(org.bukkit.block.BlockState) Conduit(org.bukkit.block.Conduit) Beacon(org.bukkit.block.Beacon) Skull(org.bukkit.block.Skull) Sign(org.bukkit.block.Sign) Structure(org.bukkit.block.Structure) EnchantingTable(org.bukkit.block.EnchantingTable) EnderChest(org.bukkit.block.EnderChest) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Example 47 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class ProjectileEventListener method onProjectileHit.

@EventHandler
public void onProjectileHit(ProjectileHitEvent event) {
    Projectile entity = event.getEntity();
    Location location = BukkitUtil.adapt(entity.getLocation());
    if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
        return;
    }
    PlotArea area = location.getPlotArea();
    if (area == null) {
        return;
    }
    Plot plot = area.getPlot(location);
    ProjectileSource shooter = entity.getShooter();
    if (shooter instanceof Player) {
        PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
        if (plot == null) {
            if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
                entity.remove();
                event.setCancelled(true);
            }
            return;
        }
        if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER) || plot.getFlag(ProjectilesFlag.class)) {
            return;
        }
        entity.remove();
        event.setCancelled(true);
        return;
    }
    if (!(shooter instanceof Entity) && shooter != null) {
        if (plot == null) {
            entity.remove();
            event.setCancelled(true);
            return;
        }
        Location sLoc = BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
        if (!area.contains(sLoc.getX(), sLoc.getZ())) {
            entity.remove();
            event.setCancelled(true);
            return;
        }
        Plot sPlot = area.getOwnedPlotAbs(sLoc);
        if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
            entity.remove();
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PlotPlayer(com.plotsquared.core.player.PlotPlayer) PlotArea(com.plotsquared.core.plot.PlotArea) ProjectilesFlag(com.plotsquared.core.plot.flag.implementations.ProjectilesFlag) Plot(com.plotsquared.core.plot.Plot) ProjectileSource(org.bukkit.projectiles.ProjectileSource) BlockProjectileSource(org.bukkit.projectiles.BlockProjectileSource) BlockProjectileSource(org.bukkit.projectiles.BlockProjectileSource) Projectile(org.bukkit.entity.Projectile) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Example 48 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class ProjectileEventListener method onPotionSplash.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
    ThrownPotion damager = event.getPotion();
    Location location = BukkitUtil.adapt(damager.getLocation());
    if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
        return;
    }
    int count = 0;
    for (LivingEntity victim : event.getAffectedEntities()) {
        if (!BukkitEntityUtil.entityDamage(damager, victim)) {
            event.setIntensity(victim, 0);
            count++;
        }
    }
    if (count > 0 && count == event.getAffectedEntities().size()) {
        event.setCancelled(true);
    } else {
        // Cancelling projectile hit events still results in potions
        // splashing in the world. We need to cancel the splash events to
        // avoid that.
        onProjectileHit(event);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ThrownPotion(org.bukkit.entity.ThrownPotion) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Example 49 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class ForceFieldListener method calculateVelocity.

private static Vector calculateVelocity(PlotPlayer<?> player, PlotPlayer<?> e) {
    Location playerLocation = player.getLocationFull();
    Location oPlayerLocation = e.getLocation();
    double playerX = playerLocation.getX();
    double playerY = playerLocation.getY();
    double playerZ = playerLocation.getZ();
    double oPlayerX = oPlayerLocation.getX();
    double oPlayerY = oPlayerLocation.getY();
    double oPlayerZ = oPlayerLocation.getZ();
    double x = 0d;
    if (playerX < oPlayerX) {
        x = 1.0d;
    } else if (playerX > oPlayerX) {
        x = -1.0d;
    }
    double y = 0d;
    if (playerY < oPlayerY) {
        y = 0.5d;
    } else if (playerY > oPlayerY) {
        y = -0.5d;
    }
    double z = 0d;
    if (playerZ < oPlayerZ) {
        z = 1.0d;
    } else if (playerZ > oPlayerZ) {
        z = -1.0d;
    }
    return new Vector(x, y, z);
}
Also used : Vector(org.bukkit.util.Vector) Location(com.plotsquared.core.location.Location)

Example 50 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class PaperListener method onEntityPathfind.

@EventHandler
public void onEntityPathfind(SlimePathfindEvent event) {
    if (!Settings.Paper_Components.ENTITY_PATHING) {
        return;
    }
    Slime slime = event.getEntity();
    Block b = slime.getTargetBlock(4);
    if (b == null) {
        return;
    }
    Location toLoc = BukkitUtil.adapt(b.getLocation());
    Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
    PlotArea tarea = toLoc.getPlotArea();
    if (tarea == null) {
        return;
    }
    PlotArea farea = fromLoc.getPlotArea();
    if (farea == null) {
        return;
    }
    if (tarea != farea) {
        event.setCancelled(true);
        return;
    }
    Plot tplot = toLoc.getPlot();
    Plot fplot = fromLoc.getPlot();
    if (tplot == null ^ fplot == null) {
        event.setCancelled(true);
        return;
    }
    if (tplot == null || tplot.getId().hashCode() == fplot.getId().hashCode()) {
        return;
    }
    if (fplot.isMerged() && fplot.getConnectedPlots().contains(fplot)) {
        return;
    }
    event.setCancelled(true);
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) Block(org.bukkit.block.Block) Slime(org.bukkit.entity.Slime) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Location (com.plotsquared.core.location.Location)82 Plot (com.plotsquared.core.plot.Plot)41 PlotArea (com.plotsquared.core.plot.PlotArea)26 EventHandler (org.bukkit.event.EventHandler)15 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)14 PlotPlayer (com.plotsquared.core.player.PlotPlayer)12 UUID (java.util.UUID)12 HashSet (java.util.HashSet)10 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)9 NonNull (org.checkerframework.checker.nullness.qual.NonNull)9 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)8 Caption (com.plotsquared.core.configuration.caption.Caption)7 BlockLoc (com.plotsquared.core.location.BlockLoc)7 Template (net.kyori.adventure.text.minimessage.Template)7 Entity (org.bukkit.entity.Entity)7 Settings (com.plotsquared.core.configuration.Settings)6 ClassicPlotWorld (com.plotsquared.core.generator.ClassicPlotWorld)6 PlotFlag (com.plotsquared.core.plot.flag.PlotFlag)6 SinglePlotArea (com.plotsquared.core.plot.world.SinglePlotArea)6 PlotSquared (com.plotsquared.core.PlotSquared)5