From b216b9996f1af6c00e123540fc0b6aa6ff77d922 Mon Sep 17 00:00:00 2001 From: Beelzebu Date: Wed, 30 Jan 2019 23:52:15 -0300 Subject: [PATCH] Implement timbru31/SilkSpawners#82 --- .../listeners/SilkSpawnersBlockListener.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/SilkSpawners/src/main/java/de/dustplanet/silkspawners/listeners/SilkSpawnersBlockListener.java b/modules/SilkSpawners/src/main/java/de/dustplanet/silkspawners/listeners/SilkSpawnersBlockListener.java index c94df421..b35592a3 100644 --- a/modules/SilkSpawners/src/main/java/de/dustplanet/silkspawners/listeners/SilkSpawnersBlockListener.java +++ b/modules/SilkSpawners/src/main/java/de/dustplanet/silkspawners/listeners/SilkSpawnersBlockListener.java @@ -2,6 +2,7 @@ import java.util.HashMap; import java.util.Random; +import java.util.stream.Collectors; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -15,6 +16,7 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.permissions.PermissionAttachmentInfo; import de.dustplanet.silkspawners.SilkSpawners; import de.dustplanet.silkspawners.events.SilkSpawnersSpawnerBreakEvent; @@ -115,7 +117,23 @@ public void onBlockBreak(BlockBreakEvent event) { if (plugin.mobs.contains("creatures." + entityID + ".silkDropChance")) { dropChance = plugin.mobs.getInt("creatures." + entityID + ".silkDropChance", 100); } else { - dropChance = plugin.config.getInt("silkDropChance", 100); + for (String perm : player.getEffectivePermissions().stream().map(PermissionAttachmentInfo::getPermission).collect(Collectors.toList())) { + if (perm.startsWith("silkspawners.dropchance.")) { + try { + dropChance = Integer.parseInt(perm.split("silkspawners.dropchance.")[1]); + if (dropChance > 0) { + break; + } + } catch (NumberFormatException ignore) { + } + } + } + if (dropChance > 100) { + dropChance = 100; + } + if (dropChance <= 0) { + dropChance = plugin.config.getInt("silkDropChance", 100); + } } if (randomNumber < dropChance) {