Skip to content
Permalink
Browse files

Switched custom drops to use a list of regions called `regions`, rath…

…er than a string called `region`
  • Loading branch information...
me4502 committed Oct 14, 2016
1 parent 385877c commit 7e37e5c591c2859c6103acc558fcd3b6de52aadd
@@ -21,7 +21,7 @@
private TernaryState silkTouch;

// WorldGuard Integration
private String region;
private List<String> regions;

public CustomDropDefinition(String name, List<DropItemStack> drops, List<DropReward> extraRewards, TernaryState silkTouch) {
this.drops = drops.toArray(new DropItemStack[drops.size()]);
@@ -39,12 +39,12 @@ public boolean getAppend() {
return append;
}

public String getRegion() {
return region;
public List<String> getRegions() {
return regions;
}

public void setRegion(String region) {
this.region = region;
public void setRegions(List<String> regions) {
this.regions = regions;
}

public DropReward[] getRewards() {
@@ -62,7 +62,7 @@ public boolean load() {

boolean append = config.getBoolean("custom-drops." + key + ".append", false);
TernaryState silkTouch = TernaryState.getFromString(config.getString("custom-drops." + key + ".silk-touch", "none"));
String region = config.getString("custom-drops." + key + ".region", null);
List<String> regions = config.getStringList("custom-drops." + key + ".regions", null);

List<DropItemStack> drops = new ArrayList<DropItemStack>();

@@ -120,8 +120,8 @@ public boolean load() {

if(def != null) {
def.setAppend(append);
if (region != null) {
def.setRegion(region);
if (regions != null) {
def.setRegions(regions);
}
definitions.add(def);
}
@@ -136,8 +136,8 @@ public void save() {

config.setProperty("custom-drops." + def.getName() + ".append", def.getAppend());
config.setProperty("custom-drops." + def.getName() + ".silk-touch", def.getSilkTouch().toString());
if (def.getRegion() != null)
config.setProperty("custom-drops." + def.getName() + ".region", def.getRegion());
if (def.getRegions() != null)
config.setProperty("custom-drops." + def.getName() + ".regions", def.getRegions());

int i = 0;
for(DropItemStack stack : def.getDrops()) {
@@ -193,11 +193,18 @@ public void onBlockBreak(BlockBreakEvent event) {

if(!((BlockCustomDropDefinition) def).getBlockType().isSame(event.getBlock())) continue;

if (def.getRegion() != null) {
ProtectedRegion region = WorldGuardPlugin.inst().getRegionManager(event.getBlock().getWorld())
.getRegion(def.getRegion());
if (region == null || !region.contains(event.getBlock().getX(), event.getBlock().getY(),
event.getBlock().getZ()))
if (def.getRegions() != null) {
boolean found = false;
for (String region : def.getRegions()) {
ProtectedRegion r = WorldGuardPlugin.inst().getRegionManager(event.getBlock().getWorld())
.getRegion(region);
if (r != null && r.contains(event.getBlock().getX(), event.getBlock().getY(),
event.getBlock().getZ())) {
found = true;
break;
}
}
if (!found)
return;
}

@@ -233,11 +240,19 @@ public void onEntityDeath(EntityDeathEvent event) {

if(!((EntityCustomDropDefinition) def).getEntityType().equals(event.getEntityType())) continue;

if (def.getRegion() != null) {
ProtectedRegion region = WorldGuardPlugin.inst().getRegionManager(event.getEntity().getWorld())
.getRegion(def.getRegion());
if (region == null || !region.contains(event.getEntity().getLocation().getBlockX(),
event.getEntity().getLocation().getBlockX(), event.getEntity().getLocation().getBlockX()))
if (def.getRegions() != null) {
boolean found = false;
for (String region : def.getRegions()) {
ProtectedRegion r = WorldGuardPlugin.inst().getRegionManager(event.getEntity().getWorld())
.getRegion(region);
if (r != null && r.contains(event.getEntity().getLocation().getBlockX(),
event.getEntity().getLocation().getBlockY(),
event.getEntity().getLocation().getBlockZ())) {
found = true;
break;
}
}
if (!found)
return;
}

0 comments on commit 7e37e5c

Please sign in to comment.
You can’t perform that action at this time.