Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preperations for block containment checking conversion #782

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public MatchBase(Region baseRegion, MatchTeam team, List<? extends Redeemable> r
// Filters are wack. Do not allow build or break in the base region
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockBreak(BlockBreakEvent event) {
if (!baseRegion.contains(event.getBlock().getLocation())) return;
if (!baseRegion.contains(event.getBlock())) return;
event.getPlayer().sendMessage(ChatColor.RED + "You cannot break near a capture base!");
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOWEST)
public void onBlockPlace(BlockPlaceEvent event) {
if (!baseRegion.contains(event.getBlock().getLocation())) return;
if (!baseRegion.contains(event.getBlock())) return;
event.getPlayer().sendMessage(ChatColor.RED + "You cannot build near a capture base!");
event.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import network.warzone.tgm.util.Strings;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand All @@ -40,7 +41,7 @@ public class BlockBreakFilterType implements FilterType, Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPlaceEvent(BlockBreakEvent event) {
for (Region region : regions) {
if (contains(region, event.getBlock().getLocation())) {
if (contains(region, event.getBlock())) {
for (MatchTeam matchTeam : teams) {
if (matchTeam.containsPlayer(event.getPlayer())) {
FilterResult filterResult = evaluator.evaluate(event.getPlayer());
Expand All @@ -55,8 +56,8 @@ public void onBlockPlaceEvent(BlockBreakEvent event) {
}
}

private boolean contains(Region region, Location location) {
return (!inverted && region.contains(location)) || (inverted && !region.contains(location));
private boolean contains(Region region, Block block) {
return (!inverted && region.contains(block)) || (inverted && !region.contains(block));
}

private boolean canBreak(BlockBreakEvent event, FilterResult filterResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
for (Block block : event.blockList()) {
for (Region region : regions) {
FilterResult filterResult = evaluator.evaluate();
if (filterResult == FilterResult.DENY && contains(region, block.getLocation()) &&
if (filterResult == FilterResult.DENY && contains(region, block) &&
!cancelledBlocks.contains(block)) {
cancelledBlocks.add(block);
}
Expand All @@ -47,8 +47,8 @@ public void onEntityExplode(EntityExplodeEvent event) {
}
}

private boolean contains(Region region, Location location) {
return (!inverted && region.contains(location)) || (inverted && !region.contains(location));
private boolean contains(Region region, Block block) {
return (!inverted && region.contains(block)) || (inverted && !region.contains(block));
}

public static BlockExplodeFilterType parse(Match match, JsonObject jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import network.warzone.tgm.util.Strings;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand All @@ -41,7 +42,7 @@ public void onBlockPlaceEvent(PlayerInteractEvent event) {
if (event.getClickedBlock() == null) return;

for (Region region : regions) {
if (contains(region, event.getClickedBlock().getLocation())) {
if (contains(region, event.getClickedBlock())) {
for (MatchTeam matchTeam : teams) {
if (matchTeam.containsPlayer(event.getPlayer())) {
FilterResult filterResult = evaluator.evaluate(event.getPlayer());
Expand All @@ -56,8 +57,8 @@ public void onBlockPlaceEvent(PlayerInteractEvent event) {
}
}

private boolean contains(Region region, Location location) {
return (!inverted && region.contains(location)) || (inverted && !region.contains(location));
private boolean contains(Region region, Block block) {
return (!inverted && region.contains(block)) || (inverted && !region.contains(block));
}

@SuppressWarnings("ConstantConditions") // null check already passed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import network.warzone.tgm.util.Strings;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand All @@ -40,7 +41,7 @@ public class BlockPlaceFilterType implements FilterType, Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPlaceEvent(BlockPlaceEvent event) {
for (Region region : regions) {
if (contains(region, event.getBlockPlaced().getLocation())) {
if (contains(region, event.getBlockPlaced())) {
for (MatchTeam matchTeam : teams) {
if (matchTeam.containsPlayer(event.getPlayer())) {
FilterResult filterResult = evaluator.evaluate(event.getPlayer());
Expand All @@ -55,8 +56,8 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) {
}
}

private boolean contains(Region region, Location location) {
return (!inverted && region.contains(location)) || (inverted && !region.contains(location));
private boolean contains(Region region, Block block) {
return (!inverted && region.contains(block)) || (inverted && !region.contains(block));
}

private boolean canPlace(BlockPlaceEvent event, FilterResult filterResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BuildFilterType implements FilterType, Listener {
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
for (Region region : regions) {
if (contains(region, event.getBlockPlaced().getLocation())) {
if (contains(region, event.getBlockPlaced())) {
for (MatchTeam matchTeam : teams) {
if (matchTeam.containsPlayer(event.getPlayer())) {
FilterResult filterResult = evaluator.evaluate(event.getPlayer());
Expand All @@ -61,7 +61,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
for (Region region : regions) {
if (contains(region, event.getBlock().getLocation())) {
if (contains(region, event.getBlock())) {
for (MatchTeam matchTeam : teams) {
if (matchTeam.containsPlayer(event.getPlayer())) {
FilterResult filterResult = evaluator.evaluate(event.getPlayer());
Expand All @@ -79,7 +79,7 @@ public void onBlockBreak(BlockBreakEvent event) {

@EventHandler
public void onPlayerClickItemFram(PlayerInteractEntityEvent event) {
if (!event.isCancelled() && event.getRightClicked() != null && event.getRightClicked() instanceof ItemFrame) {
if (!event.isCancelled() && event.getRightClicked() instanceof ItemFrame) {
for (Region region : regions) {
if (contains(region, event.getRightClicked().getLocation())) {
for (MatchTeam matchTeam : teams) {
Expand Down Expand Up @@ -184,6 +184,10 @@ public void onPistonRetract(BlockPistonRetractEvent event) {
}
}

private boolean contains(Region region, Block block) {
return (!inverted && region.contains(block)) || (inverted && !region.contains(block));
}

private boolean contains(Region region, Location location) {
return (!inverted && region.contains(location)) || (inverted && !region.contains(location));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class VoidBuildFilterType implements FilterType, Listener {
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
for (Region region : regions) {
if (contains(region, event.getBlockPlaced().getLocation())) {
if (contains(region, event.getBlockPlaced())) {
for (MatchTeam matchTeam : teams) {
if (matchTeam.containsPlayer(event.getPlayer())) {
FilterResult filterResult = evaluator.evaluate(event.getPlayer());
Expand All @@ -63,8 +63,8 @@ public void onBlockPlace(BlockPlaceEvent event) {
}
}

private boolean contains(Region region, Location location) {
return (!inverted && region.contains(location)) || (inverted && !region.contains(location));
private boolean contains(Region region, Block block) {
return (!inverted && region.contains(block)) || (inverted && !region.contains(block));
}

private boolean isAboveVoid(Block placed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public MatchFlag(List<Pattern> bannerPatterns, String bannerType, String rotatio

TGM.registerEvents(this);

if (bannerType.contains("WALL")) {
if (bannerType.contains("WALL")) { // TODO: Adjust this region when switching from block positions to coordinates
this.protectiveRegion = new CuboidRegion(
location.clone().subtract(1, 2, 1),
location.clone().add(1, 1, 1)
Expand All @@ -159,14 +159,14 @@ public MatchFlag(List<Pattern> bannerPatterns, String bannerType, String rotatio
// Filters are wack. Do not allow build or break in the base region
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockBreak(BlockBreakEvent event) {
if (!protectiveRegion.contains(event.getBlock().getLocation())) return;
if (!protectiveRegion.contains(event.getBlock())) return;
event.getPlayer().sendMessage(ChatColor.RED + "You cannot break near a flag area!");
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOWEST)
public void onBlockPlace(BlockPlaceEvent event) {
if (!protectiveRegion.contains(event.getBlock().getLocation())) return;
if (!protectiveRegion.contains(event.getBlock())) return;
event.getPlayer().sendMessage(ChatColor.RED + "You cannot build near a flag area!");
event.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Monument implements Listener {

@EventHandler(priority = EventPriority.LOWEST)
public void onBlockBreak(BlockBreakEvent event) {
if (region.contains(event.getBlock().getLocation())) {
if (region.contains(event.getBlock())) {
if (materials == null || materials.contains(event.getBlock().getType())) {
if (!canDamage(event.getPlayer())) {
event.getPlayer().sendMessage(ChatColor.RED + "You cannot damage a monument you own.");
Expand All @@ -54,7 +54,7 @@ public void onBlockBreak(BlockBreakEvent event) {
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreakHighest(BlockBreakEvent event) {
if (region.contains(event.getBlock().getLocation())) {
if (region.contains(event.getBlock())) {
if (materials == null || materials.contains(event.getBlock().getType())) {
if (canDamage(event.getPlayer())) {
Match match = this.match.get();
Expand Down Expand Up @@ -83,7 +83,7 @@ public void onBlockBreakHighest(BlockBreakEvent event) {

@EventHandler
public void onBlockBurn(BlockBurnEvent event) {
if (region.contains(event.getBlock().getLocation())) {
if (region.contains(event.getBlock())) {
if (materials == null || materials.contains(event.getBlock().getType())) {
event.setCancelled(true);
}
Expand All @@ -92,20 +92,20 @@ public void onBlockBurn(BlockBurnEvent event) {

@EventHandler(priority = EventPriority.HIGH)
public void onBlockIgniteEvent(BlockIgniteEvent event) {
if (region.contains(event.getBlock().getLocation())) {
if (region.contains(event.getBlock())) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPistonRetract(BlockPistonRetractEvent event) {
if (region.contains(event.getBlock().getLocation())) {
if (region.contains(event.getBlock())) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGH)
public void onPistonExtend(BlockPistonExtendEvent event) {
if (region.contains(event.getBlock().getLocation())) {
if (region.contains(event.getBlock())) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<Block> getBlocks() {
List<Block> results = new ArrayList<>();
CuboidRegion bound = new CuboidRegion(getMin(), getMax());
for (Block block : bound.getBlocks()) {
if (contains(new Location(TGM.get().getMatchManager().getMatch().getWorld(), block.getX(), block.getY(), block.getZ()))) results.add(block);
if (contains(block)) results.add(block);
}
return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public List<Block> getBlocks() {
List<Block> results = new ArrayList<>();
CuboidRegion bound = new CuboidRegion(this.min, this.max);
for (Block block : bound.getBlocks()) {
if (contains(new Location(focalPoint.getWorld(), block.getX(), block.getY(), block.getZ()))) results.add(block);
if (contains(block)) results.add(block);
}
return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<Block> getBlocks() {
List<Block> results = new ArrayList<>();
CuboidRegion bound = new CuboidRegion(getMin(), getMax());
for (Block block : bound.getBlocks()) {
if (contains(new Location(TGM.get().getMatchManager().getMatch().getWorld(), block.getX(), block.getY(), block.getZ()))) results.add(block);
if (contains(block)) results.add(block);
}
return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public WoolObjective(String name, Material block, MatchTeam owner, Region podium
@EventHandler(priority = EventPriority.LOWEST)
public void onPlace(BlockPlaceEvent event) {
if (event.getBlockPlaced().getType() == block) {
if (!completed && podium.contains(event.getBlockPlaced().getLocation()) && owner.containsPlayer(event.getPlayer()))
if (!completed && podium.contains(event.getBlockPlaced()) && owner.containsPlayer(event.getPlayer()))
event.setCancelled(true);
} else {
if (podium.contains(event.getBlockPlaced().getLocation())) {
if (podium.contains(event.getBlockPlaced())) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You may only place " + ChatColor.YELLOW + ItemUtils.materialToString(block) + ChatColor.RED + " in the podium!");
}
Expand All @@ -80,7 +80,7 @@ public void onPlace(BlockPlaceEvent event) {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlaceHighest(BlockPlaceEvent event) {
if (!completed && event.getBlockPlaced().getType() == block) {
if (!podium.contains(event.getBlockPlaced().getLocation())) {
if (!podium.contains(event.getBlockPlaced())) {
return;
}
if (!owner.containsPlayer(event.getPlayer())) {
Expand Down