Implemented allowed-items as break-prerequisite
This commit is contained in:
parent
b61cbeb350
commit
15b015874d
21
config.yml
21
config.yml
@ -6,25 +6,32 @@ break:
|
|||||||
break-prerequisite:
|
break-prerequisite:
|
||||||
# 'unknown' means we dont know where the spawner came from (usually a generated one or e.g. using worldedit)
|
# 'unknown' means we dont know where the spawner came from (usually a generated one or e.g. using worldedit)
|
||||||
UNKNOWN:
|
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
|
# 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
|
silktouch: true
|
||||||
# messages for success or failure
|
# messages for success or failure
|
||||||
msg:
|
msg:
|
||||||
success: ''
|
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:
|
PLAYER:
|
||||||
|
allowed-items:
|
||||||
|
- 'diamond_pickaxe'
|
||||||
silktouch: true
|
silktouch: true
|
||||||
msg:
|
msg:
|
||||||
success: ''
|
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:
|
ADMIN:
|
||||||
|
allowed-items:
|
||||||
|
- 'diamond_pickaxe'
|
||||||
silktouch: true
|
silktouch: true
|
||||||
msg:
|
msg:
|
||||||
success: ''
|
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:
|
drop:
|
||||||
@ -36,18 +43,24 @@ break:
|
|||||||
drop-prerequisite:
|
drop-prerequisite:
|
||||||
|
|
||||||
UNKNOWN:
|
UNKNOWN:
|
||||||
|
allowed-items:
|
||||||
|
- 'diamond_pickaxe'
|
||||||
silktouch: true
|
silktouch: true
|
||||||
msg:
|
msg:
|
||||||
success: '§7§oThe spawner breaks with a loud *Pop* and falls to the ground to be picked up'
|
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'
|
fail: '§7§o*Poof* The spawner breaks into many pieces and is lost'
|
||||||
|
|
||||||
PLAYER:
|
PLAYER:
|
||||||
|
allowed-items:
|
||||||
|
- 'diamond_pickaxe'
|
||||||
silktouch: true
|
silktouch: true
|
||||||
msg:
|
msg:
|
||||||
success: ''
|
success: ''
|
||||||
fail: '§7§o*Poof* The spawner breaks into many pieces and is lost'
|
fail: '§7§o*Poof* The spawner breaks into many pieces and is lost'
|
||||||
|
|
||||||
ADMIN:
|
ADMIN:
|
||||||
|
allowed-items:
|
||||||
|
- 'diamond_pickaxe'
|
||||||
silktouch: true
|
silktouch: true
|
||||||
msg:
|
msg:
|
||||||
success: '§7§oThe spawner breaks with a loud *Pop* and falls to the ground to be picked up'
|
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 org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class OnBlockBreak implements Listener {
|
public class OnBlockBreak implements Listener {
|
||||||
|
|
||||||
@ -45,14 +46,29 @@ public class OnBlockBreak implements Listener {
|
|||||||
|
|
||||||
// # Break-Prerequisite
|
// # Break-Prerequisite
|
||||||
ConfigurationSection breakPreConfig = Main.config.getConfigurationSection("break.break-prerequisite."+ bSource);
|
ConfigurationSection breakPreConfig = Main.config.getConfigurationSection("break.break-prerequisite."+ bSource);
|
||||||
boolean success = false;
|
boolean success = true;
|
||||||
// Silktouch
|
// Allowed-items
|
||||||
if(breakPreConfig.getBoolean("silktouch")){
|
List<String> allowed_items = (List<String>) breakPreConfig.getList("allowed-items");
|
||||||
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
|
if(allowed_items != null){
|
||||||
success = true;
|
boolean found = false;
|
||||||
else
|
for(String allowed_item : allowed_items){
|
||||||
e.setCancelled(true);
|
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
|
// Send msg
|
||||||
String msg = breakPreConfig.getString("msg."+ (success?"success":"fail"));
|
String msg = breakPreConfig.getString("msg."+ (success?"success":"fail"));
|
||||||
if(msg != null && !msg.equals("")) p.sendMessage(msg);
|
if(msg != null && !msg.equals("")) p.sendMessage(msg);
|
||||||
@ -78,15 +94,30 @@ public class OnBlockBreak implements Listener {
|
|||||||
|
|
||||||
// # Drop-Prerequisite
|
// # Drop-Prerequisite
|
||||||
ConfigurationSection dropPreConfig = Main.config.getConfigurationSection("break.drop-prerequisite."+ bSource);
|
ConfigurationSection dropPreConfig = Main.config.getConfigurationSection("break.drop-prerequisite."+ bSource);
|
||||||
boolean success = false;
|
boolean success = true;
|
||||||
// Silktouch
|
// Allowed-items
|
||||||
if(dropPreConfig.getBoolean("silktouch")){
|
List<String> allowed_items = (List<String>) dropPreConfig.getList("allowed-items");
|
||||||
if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
|
if(allowed_items != null){
|
||||||
success = true;
|
boolean found = false;
|
||||||
else
|
for(String allowed_item : allowed_items){
|
||||||
e.setCancelled(true);
|
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
|
// Set drop
|
||||||
if(success){
|
if(success){
|
||||||
ConfigurationSection dropConfig = Main.config.getConfigurationSection("break.drop");
|
ConfigurationSection dropConfig = Main.config.getConfigurationSection("break.drop");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user