Java Code Examples for org.spongepowered.api.data.Transaction#setValid()

The following examples show how to use org.spongepowered.api.data.Transaction#setValid() . 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: ExplosionListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onExplosion(ExplosionEvent.Post event)
{
	if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (event.getTransactions().size() > 100)
	{
           event.setCancelled(true);
	}
	for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
           BlockSnapshot blockSnapshot = transaction.getOriginal();
           if (blockSnapshot.getLocation().isPresent() && !DataHandler.getFlag("explosions", blockSnapshot.getLocation().get()))
   		{
           	transaction.setValid(false);
   		}
	}

}
 
Example 2
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 3
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 4
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);
        }
    }
}