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

Apply generator protection radius for normal blocks #826

Open
wants to merge 3 commits 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 @@ -22,6 +22,7 @@

import com.andrei1058.bedwars.api.arena.IArena;
import com.andrei1058.bedwars.api.arena.team.ITeam;
import com.andrei1058.bedwars.api.region.Region;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -88,6 +89,11 @@ public interface IGenerator {
* Get the generator location.
*/
Location getLocation();

/**
* Get generator region
*/
Region getRegion();

/**
* Get generator ore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public class ConfigPath {
public static final String ARENA_SPAWN_PROTECTION = "spawn-protection";
public static final String ARENA_SHOP_PROTECTION = "shop-protection";
public static final String ARENA_UPGRADES_PROTECTION = "upgrades-protection";
public static final String ARENA_GENERATOR_PROTECTION = "generator-protection";
public static final String ARENA_GENERATOR_PROTECTION_RADIUS = "generator-protection-radius";
public static final String ARENA_GENERATOR_PROTECTION_MAX_Y = "generator-protection-max-y";
public static final String ARENA_GENERATOR_PROTECTION_MIN_Y = "generator-protection-min-y";
public static final String ARENA_DISABLE_GENERATOR_FOR_EMPTY_TEAMS = "disable-generator-for-empty-teams";
public static final String ARENA_DISABLE_NPCS_FOR_EMPTY_TEAMS = "disable-npcs-for-empty-teams";
public static final String ARENA_ISLAND_RADIUS = "island-radius";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,6 @@ public static boolean isBuildProtected(Location l, IArena a) {
return true;
}
}
for (ITeam t : a.getTeams()) {
for (IGenerator o : t.getGenerators()) {
if (o.getLocation().distance(l) <= 1) {
return true;
}
}
}
for (IGenerator o : a.getOreGenerators()) {
if (o.getLocation().distance(l) <= 1) {
return true;
}
}
return isOutsideOfBorder(l);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.andrei1058.bedwars.api.language.Language;
import com.andrei1058.bedwars.api.language.Messages;
import com.andrei1058.bedwars.api.region.Cuboid;
import com.andrei1058.bedwars.api.region.Region;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -58,6 +59,7 @@ public class OreGenerator implements IGenerator {
private GeneratorType type;
private int rotate = 0, dropID = 0;
private ITeam bwt;
private Region region;
boolean up = true;

/**
Expand All @@ -82,10 +84,11 @@ public OreGenerator(Location location, IArena arena, GeneratorType type, ITeam b
loadDefaults();
BedWars.debug("Initializing new generator at: " + location + " - " + type + " - " + (bwt == null ? "NOTEAM" : bwt.getName()));

Cuboid c = new Cuboid(location, 1, true);
c.setMaxY(c.getMaxY() + 5);
c.setMinY(c.getMinY() - 2);
Cuboid c = new Cuboid(location, arena.getConfig().getInt(ConfigPath.ARENA_GENERATOR_PROTECTION_RADIUS), true);
c.setMaxY(location.getBlockY() + arena.getConfig().getInt(ConfigPath.ARENA_GENERATOR_PROTECTION_MAX_Y));
c.setMinY(location.getBlockY() - arena.getConfig().getInt(ConfigPath.ARENA_GENERATOR_PROTECTION_MIN_Y));
arena.getRegionsList().add(c);
this.region = c;
}

@Override
Expand Down Expand Up @@ -371,6 +374,11 @@ public Location getLocation() {
return location;
}

@Override
public Region getRegion() {
return region;
}

@Override
public ItemStack getOre() {
return ore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public ArenaConfig(Plugin plugin, String name, String dir) {
yml.addDefault(ConfigPath.ARENA_SPAWN_PROTECTION, 5);
yml.addDefault(ConfigPath.ARENA_SHOP_PROTECTION, 1);
yml.addDefault(ConfigPath.ARENA_UPGRADES_PROTECTION, 1);
yml.addDefault(ConfigPath.ARENA_GENERATOR_PROTECTION, 1);
yml.addDefault(ConfigPath.ARENA_GENERATOR_PROTECTION_RADIUS, 1);
yml.addDefault(ConfigPath.ARENA_GENERATOR_PROTECTION_MAX_Y, 5);
yml.addDefault(ConfigPath.ARENA_GENERATOR_PROTECTION_MIN_Y, 2);
yml.addDefault(ConfigPath.ARENA_ISLAND_RADIUS, 17);
yml.addDefault("worldBorder", 300);
yml.addDefault(ConfigPath.ARENA_Y_LEVEL_KILL, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,15 @@ public void onBucketEmpty(PlayerBucketEmptyEvent e) {
return;
}
for (IGenerator o : t.getGenerators()) {
if (o.getLocation().distance(e.getBlockClicked().getLocation()) <= a.getConfig().getInt(ConfigPath.ARENA_GENERATOR_PROTECTION)) {
if (o.getRegion().isInRegion(e.getBlockClicked().getLocation())) {
e.setCancelled(true);
p.sendMessage(getMsg(p, Messages.INTERACT_CANNOT_PLACE_BLOCK));
return;
}
}
}
for (IGenerator o : a.getOreGenerators()) {
if (o.getLocation().distance(e.getBlockClicked().getLocation()) <= a.getConfig().getInt(ConfigPath.ARENA_GENERATOR_PROTECTION)) {
if (o.getRegion().isInRegion(e.getBlockClicked().getLocation())) {
e.setCancelled(true);
p.sendMessage(getMsg(p, Messages.INTERACT_CANNOT_PLACE_BLOCK));
return;
Expand Down