Skip to content

Commit

Permalink
Add support for filter in fill action
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
  • Loading branch information
Pablete1234 committed Nov 26, 2022
1 parent 9c8ad73 commit 6f61750
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/src/main/java/tc/oc/pgm/action/ActionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public FillAction parseFill(Element el, Class<?> scope) throws InvalidXMLExcepti
return new FillAction(
regions.parseProperty(Node.fromAttrOrSelf(el, "region"), BlockBoundedValidation.INSTANCE),
XMLUtils.parseMaterialData(Node.fromRequiredAttr(el, "material")),
filters.parseProperty(Node.fromAttr(el, "filter")),
XMLUtils.parseBoolean(el.getAttribute("events"), false));
}
}
10 changes: 9 additions & 1 deletion core/src/main/java/tc/oc/pgm/action/actions/FillAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,33 @@
import org.bukkit.block.BlockState;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.material.MaterialData;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.api.filter.Filter;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.region.Region;
import tc.oc.pgm.filters.query.BlockQuery;

public class FillAction extends AbstractAction<Match> {

private final Region region;
private final MaterialData materialData;
private final @Nullable Filter filter;
private final boolean events;

public FillAction(Region region, MaterialData materialData, boolean events) {
public FillAction(
Region region, MaterialData materialData, @Nullable Filter filter, boolean events) {
super(Match.class);
this.region = region;
this.materialData = materialData;
this.filter = filter;
this.events = events;
}

@Override
public void trigger(Match match) {
for (Block block : region.getBlocks(match.getWorld())) {
if (filter != null && filter.query(new BlockQuery(block)).isDenied()) continue;

BlockState newState = block.getState();
newState.setMaterialData(materialData);

Expand Down

0 comments on commit 6f61750

Please sign in to comment.