Permalink
Browse files

Added per-drop permission nodes to custom drops.

  • Loading branch information...
me4502 committed Jul 23, 2017
1 parent 0474504 commit 2ff610ce4758349d499f85ceafb7560a6cca6ff6
@@ -17,6 +17,7 @@
private DropItemStack[] drops;
private DropReward[] extraRewards;
private String name;
private String permissionNode;
private boolean append;
private TernaryState silkTouch;
@@ -36,6 +37,14 @@ public CustomDropDefinition(String name, List<DropItemStack> drops, List<DropRew
this.silkTouch = silkTouch;
}
public void setPermissionNode(String permissionNode) {
this.permissionNode = permissionNode;
}
public String getPermissionNode() {
return permissionNode;
}
public void setAppend(boolean append) {
this.append = append;
}
@@ -126,6 +126,7 @@ public boolean load() {
if (regions != null) {
def.setRegions(regions);
}
def.setPermissionNode(config.getString("custom-drops." + key + ".permission-node", null));
if (requiredItems != null) {
List<ItemStack> items = new ArrayList<>();
for (String requiredItem : requiredItems) {
@@ -158,6 +159,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.getPermissionNode() != null)
config.setProperty("custom-drops." + def.getName() + ".permission-node", def.getPermissionNode());
if (def.getRegions() != null)
config.setProperty("custom-drops." + def.getName() + ".regions", def.getRegions());
if (def.getItems() != null) {
@@ -229,6 +232,10 @@ public void onBlockBreak(BlockBreakEvent event) {
if(!((BlockCustomDropDefinition) def).getBlockType().isSame(event.getBlock())) continue;
if (def.getPermissionNode() != null && !CraftBookPlugin.inst().wrapPlayer(event.getPlayer()).hasPermission(def.getPermissionNode())) {
return;
}
if (def.getRegions() != null) {
boolean found = false;
for (String region : def.getRegions()) {
@@ -306,6 +313,12 @@ public void onEntityDeath(EntityDeathEvent event) {
if(!((EntityCustomDropDefinition) def).getEntityType().equals(event.getEntityType())) continue;
if (def.getPermissionNode() != null) {
if (event.getEntity().getKiller() == null
|| !CraftBookPlugin.inst().wrapPlayer(event.getEntity().getKiller()).hasPermission(def.getPermissionNode()))
return;
}
if (def.getRegions() != null) {
boolean found = false;
for (String region : def.getRegions()) {

0 comments on commit 2ff610c

Please sign in to comment.