Implemented allowed-items as break-prerequisite

master
Alexander B 4 years ago
parent b61cbeb350
commit 15b015874d

@ -6,25 +6,32 @@ break:
break-prerequisite:
# 'unknown' means we dont know where the spawner came from (usually a generated one or e.g. using worldedit)
UNKNOWN:
# Which items are allowed to break a spawner (null to allow everything)
allowed-items:
- 'diamond_pickaxe'
# silktouch-enchantment is needed to be able to break this block
# if set to false, any break is considered a 'success'
# if everything is set to false, any break is considered a 'success'
silktouch: true
# messages for success or failure
msg:
success: ''
fail: '§7§oNothing happens, it seems you cannot break the spawner without the Silktouch-enchantment'
fail: '§7§oNothing happens, it seems you need a diamond-pickaxe with silktouch'
PLAYER:
allowed-items:
- 'diamond_pickaxe'
silktouch: true
msg:
success: ''
fail: '§7§oNothing happens, it seems you cannot break the spawner without the Silktouch-enchantment'
fail: '§7§oNothing happens, it seems you need a diamond-pickaxe with silktouch'
ADMIN:
allowed-items:
- 'diamond_pickaxe'
silktouch: true
msg:
success: ''
fail: '§7§oNothing happens, it seems you cannot break the spawner without the Silktouch-enchantment'
fail: '§7§oNothing happens, it seems you need a diamond-pickaxe with silktouch'
drop:
@ -36,18 +43,24 @@ break:
drop-prerequisite:
UNKNOWN:
allowed-items:
- 'diamond_pickaxe'
silktouch: true
msg:
success: '§7§oThe spawner breaks with a loud *Pop* and falls to the ground to be picked up'
fail: '§7§o*Poof* The spawner breaks into many pieces and is lost'
PLAYER:
allowed-items:
- 'diamond_pickaxe'
silktouch: true
msg:
success: ''
fail: '§7§o*Poof* The spawner breaks into many pieces and is lost'
ADMIN:
allowed-items:
- 'diamond_pickaxe'
silktouch: true
msg:
success: '§7§oThe spawner breaks with a loud *Pop* and falls to the ground to be picked up'

@ -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;
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(breakPreConfig.getBoolean("silktouch")){
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
success = true;
else
e.setCancelled(true);
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;
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(dropPreConfig.getBoolean("silktouch")){
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
success = true;
else
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");

Loading…
Cancel
Save