Implemented allowed-items as break-prerequisite

This commit is contained in:
Alexander B
2021-01-05 21:18:25 +01:00
parent b61cbeb350
commit 15b015874d
2 changed files with 62 additions and 18 deletions

View File

@@ -17,6 +17,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import java.io.IOException;
import java.util.List;
public class OnBlockBreak implements Listener {
@@ -45,14 +46,29 @@ public class OnBlockBreak implements Listener {
// # Break-Prerequisite
ConfigurationSection breakPreConfig = Main.config.getConfigurationSection("break.break-prerequisite."+ bSource);
boolean success = false;
// Silktouch
if(breakPreConfig.getBoolean("silktouch")){
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
success = true;
else
e.setCancelled(true);
boolean success = true;
// Allowed-items
List<String> allowed_items = (List<String>) breakPreConfig.getList("allowed-items");
if(allowed_items != null){
boolean found = false;
for(String allowed_item : allowed_items){
if(p.getItemInHand().getType().name().equalsIgnoreCase(allowed_item)){
found = true;
break;
}
}
if(!found) success = false;
}
// Silktouch
if(success && breakPreConfig.getBoolean("silktouch")){
if(!p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)){
success = false;
}
}
if(!success) e.setCancelled(true);
// Send msg
String msg = breakPreConfig.getString("msg."+ (success?"success":"fail"));
if(msg != null && !msg.equals("")) p.sendMessage(msg);
@@ -78,15 +94,30 @@ public class OnBlockBreak implements Listener {
// # Drop-Prerequisite
ConfigurationSection dropPreConfig = Main.config.getConfigurationSection("break.drop-prerequisite."+ bSource);
boolean success = false;
// Silktouch
if(dropPreConfig.getBoolean("silktouch")){
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
success = true;
else
e.setCancelled(true);
boolean success = true;
// Allowed-items
List<String> allowed_items = (List<String>) dropPreConfig.getList("allowed-items");
if(allowed_items != null){
boolean found = false;
for(String allowed_item : allowed_items){
if(p.getItemInHand().getType().name().equalsIgnoreCase(allowed_item)){
found = true;
break;
}
}
if(!found) success = false;
}
// Silktouch
if(success && dropPreConfig.getBoolean("silktouch")){
if(!p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)){
e.setCancelled(true);
success = false;
}
}
if(!success) e.setCancelled(true);
// Set drop
if(success){
ConfigurationSection dropConfig = Main.config.getConfigurationSection("break.drop");