org.spongepowered.api.world.LocatableBlock Java Examples

The following examples show how to use org.spongepowered.api.world.LocatableBlock. 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: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event");

    BlockState sourceState = locatable.getBlockState();

    //liquid check
    MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
    if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
        e.getLocations().forEach(loc -> {
            Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());
            if (r == null) {
                boolean flow = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.liquid_flow;
                boolean allowWater = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.water_flow;
                boolean allowLava = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.lava_flow;

                if (!flow)
                    e.setCancelled(true);
                if (!allowWater && (loc.getBlockType() == BlockTypes.WATER || loc.getBlockType() == BlockTypes.FLOWING_WATER))
                    e.setCancelled(true);
                if (!allowLava && (loc.getBlockType() == BlockTypes.LAVA || loc.getBlockType() == BlockTypes.FLOWING_LAVA))
                    e.setCancelled(true);
            }
        });
    }
}
 
Example #2
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGeneric(ChangeBlockEvent.Break e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event");

    LocatableBlock locatable = e.getCause().first(LocatableBlock.class).orElse(null);
    if (locatable != null) {
        BlockState sourceState = locatable.getBlockState();

        //liquid check
        MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
        if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
            boolean allowdamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.flow_damage;

            Region r = RedProtect.get().rm.getTopRegion(locatable.getLocation(), this.getClass().getName());
            if (r == null && !allowdamage && locatable.getLocation().getBlockType() != BlockTypes.AIR) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example #3
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(ChangeBlockEvent.Place e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onFireSpread event!");

    BlockState sourceState = locatable.getBlockState();

    if (e.getTransactions().get(0).getFinal().getState().getType().equals(BlockTypes.FIRE) &&
            (sourceState.getType() == BlockTypes.FIRE || sourceState.getType() == BlockTypes.LAVA || sourceState.getType() == BlockTypes.FLOWING_LAVA)) {
        boolean fireDamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).fire_spread;
        if (!fireDamage) {
            Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get(), this.getClass().getName());
            if (r == null) {
                RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to PLACE FIRE!");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #4
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(ChangeBlockEvent.Break e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event");

    BlockState sourceState = locatable.getBlockState();

    if (sourceState.getType() == BlockTypes.FIRE) {
        BlockSnapshot b = e.getTransactions().get(0).getOriginal();
        boolean fireDamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).fire_block_damage;
        if (!fireDamage && b.getState().getType() != BlockTypes.FIRE) {
            Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
            if (r == null) {
                RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to break from FIRE!");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #5
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event");

    BlockState sourceState = locatable.getBlockState();

    //liquid check
    MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
    if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
        e.getLocations().forEach(loc -> {
            Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());
            if (r != null && !r.canFlow()) {
                e.setCancelled(true);
            }
        });
    }
}
 
Example #6
Source File: BlockEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
public GDClaim getSourceClaim(Cause cause) {
    BlockSnapshot blockSource = cause.first(BlockSnapshot.class).orElse(null);
    LocatableBlock locatableBlock = null;
    TileEntity tileEntitySource = null;
    Entity entitySource = null;
    if (blockSource == null) {
        locatableBlock = cause.first(LocatableBlock.class).orElse(null);
        if (locatableBlock == null) {
            entitySource = cause.first(Entity.class).orElse(null);
        }
        if (locatableBlock == null && entitySource == null) {
            tileEntitySource = cause.first(TileEntity.class).orElse(null);
        }
    }

    GDClaim sourceClaim = null;
    if (blockSource != null) {
        sourceClaim = this.dataStore.getClaimAt(blockSource.getLocation().get());
    } else if (locatableBlock != null) {
        sourceClaim = this.dataStore.getClaimAt(locatableBlock.getLocation());
    } else if (tileEntitySource != null) {
        sourceClaim = this.dataStore.getClaimAt(tileEntitySource.getLocation());
    } else if (entitySource != null) {
        Entity entity = entitySource;
        if (entity instanceof Player) {
            Player player = (Player) entity;
            GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
            sourceClaim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
        } else {
            sourceClaim = this.dataStore.getClaimAt(entity.getLocation());
        }
    }

    return sourceClaim;
}
 
Example #7
Source File: BlockEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
public GPClaim getSourceClaim(Cause cause) {
    BlockSnapshot blockSource = cause.first(BlockSnapshot.class).orElse(null);
    LocatableBlock locatableBlock = null;
    TileEntity tileEntitySource = null;
    Entity entitySource = null;
    if (blockSource == null) {
        locatableBlock = cause.first(LocatableBlock.class).orElse(null);
        if (locatableBlock == null) {
            entitySource = cause.first(Entity.class).orElse(null);
        }
        if (locatableBlock == null && entitySource == null) {
            tileEntitySource = cause.first(TileEntity.class).orElse(null);
        }
    }

    GPClaim sourceClaim = null;
    if (blockSource != null) {
        sourceClaim = this.dataStore.getClaimAt(blockSource.getLocation().get());
    } else if (locatableBlock != null) {
        sourceClaim = this.dataStore.getClaimAt(locatableBlock.getLocation());
    } else if (tileEntitySource != null) {
        sourceClaim = this.dataStore.getClaimAt(tileEntitySource.getLocation());
    } else if (entitySource != null) {
        Entity entity = entitySource;
        if (entity instanceof Player) {
            Player player = (Player) entity;
            GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
            sourceClaim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
        } else {
            sourceClaim = this.dataStore.getClaimAt(entity.getLocation());
        }
    }

    return sourceClaim;
}
 
Example #8
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(ChangeBlockEvent.Place e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is onFireSpread event!");

    BlockState sourceState = locatable.getBlockState();

    if (sourceState.getType() == BlockTypes.FIRE || sourceState.getType() == BlockTypes.LAVA || sourceState.getType() == BlockTypes.FLOWING_LAVA) {
        Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get(), this.getClass().getName());
        if (r != null && !r.canFire()) {
            RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to PLACE FIRE!");
            e.setCancelled(true);
        }
    }
}
 
Example #9
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(ChangeBlockEvent.Break e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is onBlockBreakGeneric event");

    BlockState sourceState = locatable.getBlockState();

    if (sourceState.getType() == BlockTypes.FIRE) {
        BlockSnapshot b = e.getTransactions().get(0).getOriginal();
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
        if (r != null && !r.canFire() && b.getState().getType() != BlockTypes.FIRE) {
            RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to break from FIRE!");
            e.setCancelled(true);
        }
    }
}
 
Example #10
Source File: BlockEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockNotify(NotifyNeighborBlockEvent event) {
    LocatableBlock locatableBlock = event.getCause().first(LocatableBlock.class).orElse(null);
    TileEntity tileEntity = event.getCause().first(TileEntity.class).orElse(null);
    Location<World> sourceLocation = locatableBlock != null ? locatableBlock.getLocation() : tileEntity != null ? tileEntity.getLocation() : null;
    GDClaim sourceClaim = null;
    GDPlayerData playerData = null;
    if (sourceLocation != null) {
        if (GriefDefenderPlugin.isSourceIdBlacklisted("block-notify", event.getSource(), sourceLocation.getExtent().getProperties())) {
            return;
        }
    }

    final User user = CauseContextHelper.getEventUser(event);
    if (user == null) {
        return;
    }
    if (sourceLocation == null) {
        Player player = event.getCause().first(Player.class).orElse(null);
        if (player == null) {
            return;
        }

        sourceLocation = player.getLocation();
        playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
        sourceClaim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    } else {
        playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(sourceLocation.getExtent(), user.getUniqueId());
        sourceClaim = this.dataStore.getClaimAt(sourceLocation);
    }

    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(sourceLocation.getExtent().getUniqueId())) {
        return;
    }

    GDTimings.BLOCK_NOTIFY_EVENT.startTimingIfSync();
    Iterator<Direction> iterator = event.getNeighbors().keySet().iterator();
    GDClaim targetClaim = null;
    while (iterator.hasNext()) {
        Direction direction = iterator.next();
        Location<World> location = sourceLocation.getBlockRelative(direction);
        Vector3i pos = location.getBlockPosition();
        targetClaim = this.dataStore.getClaimAt(location, targetClaim);
        if (sourceClaim.isWilderness() && targetClaim.isWilderness()) {
            if (playerData != null) {
                playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE);
            }
            continue;
        } else if (!sourceClaim.isWilderness() && targetClaim.isWilderness()) {
            if (playerData != null) {
                playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE);
            }
            continue;
        } else if (sourceClaim.getUniqueId().equals(targetClaim.getUniqueId())) {
            if (playerData != null) {
                playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE);
            }
            continue;
        } else {
            if (playerData.eventResultCache != null && playerData.eventResultCache.checkEventResultCache(targetClaim, "block-notify") == Tristate.TRUE) {
                continue;
            }
            // Needed to handle levers notifying doors to open etc.
            if (targetClaim.isUserTrusted(user, TrustTypes.ACCESSOR)) {
                if (playerData != null) {
                    playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE, TrustTypes.ACCESSOR.getName().toLowerCase());
                }
                continue;
            }
        }

        // no claim crossing unless trusted
        iterator.remove();
    }
    GDTimings.BLOCK_NOTIFY_EVENT.stopTimingIfSync();
}
 
Example #11
Source File: RPBlockListener7.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPiston(ChangeBlockEvent.Pre e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "RPBlockListener7 - Is onChangeBlock event");

    EventContext context = e.getContext();
    Cause cause = e.getCause();
    LocatableBlock sourceLoc = cause.first(LocatableBlock.class).orElse(null);

    if (sourceLoc != null) {
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "sourceLoc");

        if (context.containsKey(EventContextKeys.PISTON_EXTEND) || context.containsKey(EventContextKeys.PISTON_RETRACT)) {
            if (RedProtect.get().config.configRoot().performance.disable_PistonEvent_handler) {
                return;
            }

            Region r = RedProtect.get().rm.getTopRegion(sourceLoc.getLocation(), this.getClass().getName());
            for (Location<World> pistonLoc : e.getLocations()) {
                Region targetr = RedProtect.get().rm.getTopRegion(pistonLoc, this.getClass().getName());

                boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper;
                RedProtect.get().logger.debug(LogLevel.BLOCKS, "getLocations");

                if (targetr != null && (r == null || r != targetr)) {
                    if (cause.first(Player.class).isPresent() && targetr.canBuild(cause.first(Player.class).get())) {
                        continue;
                    }

                    if (antih) {
                        BlockSnapshot ib = e.getLocations().get(0).add(0, 1, 0).createSnapshot();
                        if (cont.canWorldBreak(ib) || cont.canWorldBreak(e.getLocations().get(0).createSnapshot())) {
                            continue;
                        }
                    }
                    e.setCancelled(true);
                    break;
                }
            }
        }
    }
}
 
Example #12
Source File: RPBlockListener8.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPiston(ChangeBlockEvent.Pre e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "RPBlockListener8 - Is onChangeBlock event");

    EventContext context = e.getContext();
    Cause cause = e.getCause();
    LocatableBlock sourceLoc = cause.first(LocatableBlock.class).orElse(null);

    if (sourceLoc != null) {
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "sourceLoc");

        if (context.containsKey(EventContextKeys.PISTON_EXTEND) || context.containsKey(EventContextKeys.PISTON_RETRACT)) {
            if (RedProtect.get().config.configRoot().performance.disable_PistonEvent_handler) {
                return;
            }

            Region r = RedProtect.get().rm.getTopRegion(sourceLoc.getLocation(), this.getClass().getName());
            for (Location<World> pistonLoc : e.getLocations()) {
                Region targetr = RedProtect.get().rm.getTopRegion(pistonLoc, this.getClass().getName());

                boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper;
                RedProtect.get().logger.debug(LogLevel.BLOCKS, "getLocations");

                if (targetr != null && (r == null || r != targetr)) {
                    if (cause.first(Player.class).isPresent() && targetr.canBuild(cause.first(Player.class).get())) {
                        continue;
                    }

                    if (antih) {
                        BlockSnapshot ib = e.getLocations().get(0).add(0, 1, 0).createSnapshot();
                        if (cont.canWorldBreak(ib) || cont.canWorldBreak(e.getLocations().get(0).createSnapshot())) {
                            continue;
                        }
                    }
                    e.setCancelled(true);
                    break;
                }
            }
        }
    }
}