Skip to content
Permalink
Browse files

Added WorldGuard region support to CustomDrops.

  • Loading branch information...
me4502 committed Oct 2, 2016
1 parent 2d665c7 commit 385877c4d7e34e1686c82b3559723829130ef3a0
@@ -19,6 +19,7 @@
*/target
# vim
.*.sw[a-p]
dependency-reduced-pom.xml

# various other potential build files
/build
@@ -58,9 +58,8 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<version>1.10.2-R0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
@@ -184,7 +183,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<version>3.0.2</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
@@ -11,13 +11,18 @@

public abstract class CustomDropDefinition {

public static final DropReward[] EMPTY_DROP_REWARDS = new DropReward[0];

private DropItemStack[] drops;
private DropReward[] extraRewards;
private String name;

private boolean append;
private TernaryState silkTouch;

// WorldGuard Integration
private String region;

public CustomDropDefinition(String name, List<DropItemStack> drops, List<DropReward> extraRewards, TernaryState silkTouch) {
this.drops = drops.toArray(new DropItemStack[drops.size()]);
if(extraRewards != null)
@@ -27,18 +32,24 @@ public CustomDropDefinition(String name, List<DropItemStack> drops, List<DropRew
}

public void setAppend(boolean append) {

this.append = append;
}

public boolean getAppend() {

return append;
}

public String getRegion() {
return region;
}

public void setRegion(String region) {
this.region = region;
}

public DropReward[] getRewards() {
if(extraRewards == null)
extraRewards = new DropReward[0];
extraRewards = EMPTY_DROP_REWARDS;
return extraRewards;
}

@@ -8,6 +8,8 @@
import com.sk89q.craftbook.util.*;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@@ -22,10 +24,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

public class CustomDrops extends AbstractCraftBookMechanic {

@@ -36,7 +35,7 @@
@Override
public boolean enable() {

definitions = new HashSet<CustomDropDefinition>();
definitions = new LinkedHashSet<CustomDropDefinition>();

CraftBookPlugin.inst().createDefaultConfiguration(new File(CraftBookPlugin.inst().getDataFolder(), "custom-drops.yml"), "custom-drops.yml");
config = new YAMLProcessor(new File(CraftBookPlugin.inst().getDataFolder(), "custom-drops.yml"), false, YAMLFormat.EXTENDED);
@@ -63,6 +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<DropItemStack> drops = new ArrayList<DropItemStack>();

@@ -120,6 +120,9 @@ public boolean load() {

if(def != null) {
def.setAppend(append);
if (region != null) {
def.setRegion(region);
}
definitions.add(def);
}
}
@@ -133,6 +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());

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

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

boolean isSilkTouch = event.getPlayer().getItemInHand() != null && event.getPlayer().getItemInHand().getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0;
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()))
return;
}

boolean isSilkTouch = event.getPlayer().getInventory().getItemInMainHand() != null && event.getPlayer().getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0;
if(!def.getSilkTouch().doesPass(isSilkTouch))
continue;

@@ -220,7 +233,15 @@ public void onEntityDeath(EntityDeathEvent event) {

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

boolean isSilkTouch = event.getEntity() instanceof Player && ((Player) event.getEntity()).getItemInHand() != null && ((Player) event.getEntity()).getItemInHand().getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0;
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()))
return;
}

boolean isSilkTouch = event.getEntity() instanceof Player && ((Player) event.getEntity()).getInventory().getItemInMainHand() != null && ((Player) event.getEntity()).getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0;
if(!def.getSilkTouch().doesPass(isSilkTouch))
continue;

0 comments on commit 385877c

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