org.spongepowered.api.event.block.ChangeBlockEvent Java Examples

The following examples show how to use org.spongepowered.api.event.block.ChangeBlockEvent. 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: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onBreakBlock(ChangeBlockEvent.Break event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (Transaction<BlockSnapshot> transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getOriginal().getState().getType().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				event.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 onBlockBreakGlobal(ChangeBlockEvent.Break e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is BlockBreakEvent event! Cancelled? " + false);

    BlockSnapshot bt = e.getTransactions().get(0).getOriginal();
    Region r = RedProtect.get().rm.getTopRegion(bt.getLocation().get(), this.getClass().getName());
    if (r != null) {
        return;
    }

    if (!RedProtect.get().getUtil().canBuildNear(p, bt.getLocation().get())) {
        e.setCancelled(true);
        return;
    }

    if (!bypassBuild(p, bt, 2)) {
        e.setCancelled(true);
        RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Break!");
    }
}
 
Example #3
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 #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.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 #5
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 #6
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 #7
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onIceForm(ChangeBlockEvent e) {
    if (e.getTransactions().isEmpty()) return;

    Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getFinal().getLocation().get(), this.getClass().getName());

    if (r == null && (e.getTransactions().get(0).getOriginal().getState().getType().equals(BlockTypes.ICE) ||
            e.getTransactions().get(0).getOriginal().getState().getType().equals(BlockTypes.FROSTED_ICE))) {
        if (e.getCause().containsType(Player.class)) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(e.getTransactions().get(0).getFinal().getLocation().get().getExtent().getName()).iceform_by.player) {
                e.setCancelled(true);
            }
        } else if (!RedProtect.get().config.globalFlagsRoot().worlds.get(e.getTransactions().get(0).getFinal().getLocation().get().getExtent().getName()).iceform_by.entity) {
            e.setCancelled(true);
        }
    }
}
 
Example #8
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 #9
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onPlaceBlock(ChangeBlockEvent.Place event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (Transaction<BlockSnapshot> transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().getState().getType().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				event.setCancelled(true);
			}
		}
	}
}
 
Example #10
Source File: FireListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.EARLY, beforeModifications = true)
public void onFire(ChangeBlockEvent event)
{
	if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	event
	.getTransactions()
	.stream()
	.filter(trans -> trans.getFinal().getState().getType() == BlockTypes.FIRE)
	.filter(trans -> {
		Optional<Location<World>> optLoc = trans.getFinal().getLocation();
		if (!optLoc.isPresent())
			return false;
		return !DataHandler.getFlag("fire", optLoc.get());
	})
	.forEach(trans -> trans.setValid(false));
}
 
Example #11
Source File: BuildPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerPlacesBlock(ChangeBlockEvent.Place event, @First Player player)
{
	if (player.hasPermission("nations.admin.bypass.perm.build"))
	{
		return;
	}
	event
	.getTransactions()
	.stream()
	.forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> {
		if (ConfigHandler.getNode("worlds").getNode(trans.getFinal().getLocation().get().getExtent().getName()).getNode("enabled").getBoolean()
				&& !ConfigHandler.isWhitelisted("build", trans.getFinal().getState().getType().getId())
				&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
		{
			trans.setValid(false);
			try {
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
			} catch (Exception e) {}
		}
	}));
}
 
Example #12
Source File: BuildPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerChangeBlock(ChangeBlockEvent.Pre event, @First Player player)
{
	if (player.hasPermission("nations.admin.bypass.perm.build"))
	{
		return;
	}
	if (Utils.isFakePlayer(event)) {
		return;
	}
	for (Location<World> loc : event.getLocations()) {
		if (ConfigHandler.getNode("worlds").getNode(loc.getExtent().getName()).getNode("enabled").getBoolean()
				&& !ConfigHandler.isWhitelisted("break", loc.getBlock().getId())
				&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
		{
			event.setCancelled(true);
			try {
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
			} catch (Exception e) {}
			return;
		}
	}
}
 
Example #13
Source File: BuildPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerModifyBlock(ChangeBlockEvent.Modify event, @First Player player)
{
	if (player.hasPermission("nations.admin.bypass.perm.build"))
	{
		return;
	}
	event
	.getTransactions()
	.stream()
	.forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> {
		if (ConfigHandler.getNode("worlds").getNode(trans.getFinal().getLocation().get().getExtent().getName()).getNode("enabled").getBoolean()
				&& !ConfigHandler.isWhitelisted("build", trans.getFinal().getState().getType().getId())
				&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
		{
			trans.setValid(false);
			try {
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
			} catch (Exception e) {}
		}
	}));
}
 
Example #14
Source File: SignListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onSignDestroy(ChangeBlockEvent.Break event, @Root Player p) {
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockSnapshot snapshot = transaction.getOriginal();
        if (snapshot.supports(Keys.SIGN_LINES) && snapshot.getLocation().isPresent()) {
            List<Text> texts = snapshot.get(Keys.SIGN_LINES).get();
            //Checking for sign contents
            for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
                if (texts.get(0).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) {
                    if (!p.hasPermission(usign.getDestroyPermission().get())) {
                        Messages.send(p, "core.nopermissions");
                    }
                    SignDestroyEvent cevent = new SignDestroyEvent(usign, snapshot.getLocation().get(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build()));
                    Sponge.getEventManager().post(cevent);
                    if (!cevent.isCancelled() && usign.onDestroy(p, event, texts)) {
                        Messages.send(p, "sign.destroy", "%sign%", usign.getIdentifier());
                    }
                }
            }
        }
    }
}
 
Example #15
Source File: BlockprotectionListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onBreak(ChangeBlockEvent.Break event) {
    ModuleConfig config = Modules.BLOCKPROTECTION.get().getConfig().get();
    if (!config.get().getNode("protections", "allow-interact-primary").getBoolean()) return;
    Player p = event.getCause().first(Player.class).orElse(null);

    boolean modified = false;
    for (Protection prot : GlobalData.get(BlockprotectionKeys.PROTECTIONS).get()) {
        //Ignore protection if the player is allowed to modify it
        if (p != null && prot.getPlayers().contains(p.getUniqueId())) continue;
        //For each location of the protection,
        for (Transaction trans : event.getTransactions().stream().filter(trans -> trans.getFinal().getLocation().isPresent() && prot.getLocations().contains(trans.getFinal().getLocation().get())).collect(Collectors.toList())) {
            modified = true;
            trans.setValid(false);
        }

        //If anything has been cancelled & caused by player, send message
        if (p != null && modified) {
            p.sendMessage(prot.getLocktype().getErrorMessage(p, prot));
        }
    }
}
 
Example #16
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 #17
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 #18
Source File: ModifyBlockListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener
    public void onBlockModify(ChangeBlockEvent.Modify event)
    {
        User user = null;
        if(event.getCause().containsType(Player.class))
        {
            user = event.getCause().first(Player.class).get();
        }
        else if(event.getCause().containsType(User.class))
        {
            user = event.getCause().first(User.class).get();
        }

//        if(event.getContext().containsKey(EventContextKeys.OWNER)
//            && event.getContext().get(EventContextKeys.OWNER).isPresent()
//            && event.getContext().get(EventContextKeys.OWNER).get() instanceof Player)
//        {
//            Player player = (Player) event.getContext().get(EventContextKeys.OWNER).get();
        if(user != null)
        {
            for (Transaction<BlockSnapshot> transaction : event.getTransactions())
            {
                final Optional<Location<World>> optionalLocation = transaction.getFinal().getLocation();
                if(optionalLocation.isPresent() && !super.getPlugin().getProtectionManager().canInteractWithBlock(optionalLocation.get(), user, true).hasAccess())
                    event.setCancelled(true);
            }
        }
//        }
    }
 
Example #19
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 onBlockGrow(ChangeBlockEvent.Grow e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is ChangeBlockEvent.Grow event");

    BlockSnapshot b = e.getTransactions().get(0).getOriginal();
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
    if (r != null && !r.canGrow()) {
        e.setCancelled(true);
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "Cancel grow " + b.getState().getName());
    }
}
 
Example #20
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 onDecay(ChangeBlockEvent.Decay e) {
    BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockFromToEvent.Decay event is to " + bfrom.getState().getType().getName() + " from " + bfrom.getState().getType().getName());
    Region r = RedProtect.get().rm.getTopRegion(bfrom.getLocation().get(), this.getClass().getName());
    if (r != null && !r.leavesDecay()) {
        e.setCancelled(true);
    }
}
 
Example #21
Source File: JailListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player p) {
    if (event instanceof ChangeBlockEvent.Pre || event instanceof ChangeBlockEvent.Post) {
        return;
    }
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    if (up.get(JailKeys.JAIL).isPresent()) {
        if (!Modules.JAIL.get().getConfig().get().get().getNode("allow-block-modify").getBoolean()) {
            JailData data = up.get(JailKeys.JAIL).get();
            event.setCancelled(true);
            Messages.send(p, "jail.event.block", "%time%", (data.getEndtime() == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.formatDateDiff(data.getEndtime())), "%reason%", data.getReason());
        }
    }
}
 
Example #22
Source File: BlockListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onBreak(ChangeBlockEvent.Break event) {
    ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
    CommentedConfigurationNode hnode = config.get();
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        if (!trans.isValid()) continue;
        CommentedConfigurationNode node = hnode.getNode("blocks", trans.getOriginal().getState().getType().getId());
        if (!node.isVirtual()) {
            if (node.getNode("deny-break").getBoolean()) {
                trans.setValid(false);
            }
        }
    }
}
 
Example #23
Source File: BlockListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onPlace(ChangeBlockEvent.Place event) {
    ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
    CommentedConfigurationNode hnode = config.get();
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        if (!trans.isValid()) continue;
        CommentedConfigurationNode node = hnode.getNode("blocks", trans.getFinal().getState().getType().getId());
        if (!node.isVirtual() && node.getNode("deny-place").getBoolean()) {
            trans.setValid(false);
        }
    }
}
 
Example #24
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 onBlockBreak(ChangeBlockEvent.Break e, @First Player p) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is ChangeBlockEvent.Break event!");

    BlockSnapshot b = e.getTransactions().get(0).getOriginal();
    Location<World> bloc = b.getLocation().get();

    boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper;
    Region r = RedProtect.get().rm.getTopRegion(bloc, this.getClass().getName());

    if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
        BlockSnapshot ib = bloc.getBlockRelative(Direction.UP).createSnapshot();
        if ((antih && !cont.canBreak(p, ib)) || !cont.canBreak(p, b)) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.container.breakinside");
            e.setCancelled(true);
            return;
        }
    }

    if (r == null && canBreakList(p.getWorld(), b.getState().getType().getName())) {
        return;
    }

    if (r != null && b.getState().getType().equals(BlockTypes.MOB_SPAWNER) && r.allowSpawner(p)) {
        return;
    }

    if (r != null && r.canBuild(p) && b.getState().getType().getName().equalsIgnoreCase("sign")) {
        Sign s = (Sign) b.getLocation().get().getTileEntity().get();
        if (s.lines().get(0).toPlain().equalsIgnoreCase("[flag]")) {
            RedProtect.get().config.removeSign(r.getID(), b.getLocation().get());
            return;
        }
    }

    if (r != null && !r.canBuild(p) && !r.canTree(b) && !r.canMining(b) && !r.canCrops(b) && !r.canBreak(b)) {
        RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
        e.setCancelled(true);
    }
}
 
Example #25
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockGrow(ChangeBlockEvent.Grow e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is ChangeBlockEvent.Grow event");

    BlockSnapshot b = e.getTransactions().get(0).getOriginal();
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
    if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getLocation().get().getExtent().getName()).block_grow) {
        e.setCancelled(true);
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "Cancel grow " + b.getState().getName());
    }
}
 
Example #26
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBurnGlobal(ChangeBlockEvent.Modify e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBurnGlobal event");

    Transaction<BlockSnapshot> b = e.getTransactions().get(0);

    if (e.getCause().first(Monster.class).isPresent()) {
        Region r = RedProtect.get().rm.getTopRegion(b.getOriginal().getLocation().get(), this.getClass().getName());
        if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getOriginal().getLocation().get().getExtent().getName()).use_minecart) {
            e.setCancelled(true);
        }
    }
}
 
Example #27
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is ChangeBlockEvent event! Cancelled? " + false);

    BlockSnapshot b = e.getTransactions().get(0).getFinal();
    ItemType item = RedProtect.get().getVersionHelper().getItemInHand(p);
    Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get(), this.getClass().getName());

    if (r != null) {
        return;
    }

    if (!RedProtect.get().getUtil().canBuildNear(p, b.getLocation().get())) {
        e.setCancelled(true);
        return;
    }

    if (item.getName().contains("minecart") || item.getName().contains("boat")) {
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't place minecart/boat!");
        }
    } else {
        if (!bypassBuild(p, b, 1)) {
            e.setCancelled(true);
            RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Build!");
        }
    }
}
 
Example #28
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onDecay(ChangeBlockEvent.Decay e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onDecay event");

    BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
    boolean allowDecay = RedProtect.get().config.globalFlagsRoot().worlds.get(bfrom.getLocation().get().getExtent().getName()).allow_changes_of.leaves_decay;
    Region r = RedProtect.get().rm.getTopRegion(bfrom.getLocation().get(), this.getClass().getName());
    if (r == null && !allowDecay) {
        e.setCancelled(true);
    }
}
 
Example #29
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void WitherBlockBreak(ChangeBlockEvent.Break event, @First Entity e) {
    if (e instanceof Monster) {
        BlockSnapshot b = event.getTransactions().get(0).getOriginal();
        RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is EntityChangeBlockEvent event! Block " + b.getState().getType().getName());
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
        if (!cont.canWorldBreak(b)) {
            event.setCancelled(true);
            return;
        }
        if (r != null && !r.canMobLoot()) {
            event.setCancelled(true);
        }
    }
}
 
Example #30
Source File: ChangeBlockListener.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Listener
public void onPlayerChangeBlock(ChangeBlockEvent event, @Root Player player)
{
	if(EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You may not modify blocks while in jail!"));
		event.setCancelled(true);
	}
}