Fixed Custom Mining priorities.

This commit is contained in:
Aria 2019-09-27 23:00:28 +02:00
parent 783782f44f
commit 5c608b8439

View File

@ -37,8 +37,23 @@ public class BlockListener implements Listener {
*/ */
boolean customMine = MMOCore.plugin.mineManager.isEnabled(player); boolean customMine = MMOCore.plugin.mineManager.isEnabled(player);
ItemStack item = player.getInventory().getItemInMainHand(); ItemStack item = player.getInventory().getItemInMainHand();
if (customMine) {
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block.getType());
if (info == null)
return;
if (customMine) {
/*
* calls the event and listen for cancel & for drops changes... also
* allows to apply tool durability & enchants to drops, etc.
*/
CustomBlockMineEvent called = new CustomBlockMineEvent(PlayerData.get(player), block, info);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled()) {
event.setCancelled(true);
return;
}
BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType()); BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType());
if (perms == null) { if (perms == null) {
event.setCancelled(true); event.setCancelled(true);
@ -50,53 +65,39 @@ public class BlockListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
}
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block.getType()); /*
if (info == null) * remove vanilla drops if needed
return; */
if (!info.hasVanillaDrops()) {
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
}
/* /*
* calls the event and listen for cancel & for drops changes... also * apply triggers, add experience info to the event so the other events
* allows to apply tool durability & enchants to drops, etc. * can give exp to other TOOLS and display HOLOGRAMS
*/ */
CustomBlockMineEvent called = new CustomBlockMineEvent(PlayerData.get(player), block, info); if (info.hasTriggers()) {
Bukkit.getPluginManager().callEvent(called); PlayerData playerData = PlayerData.get(player);
if (called.isCancelled()) { info.getTriggers().forEach(trigger -> {
event.setCancelled(true); if(!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger)
return; trigger.apply(playerData);
} });
if(!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms())
/* MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, .5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()), player);
* remove vanilla drops if needed }
*/
if (!info.hasVanillaDrops()) { /*
event.setCancelled(true); * apply drop tables
event.getBlock().setType(Material.AIR); */
} if (info.hasDropTable()) {
Location dropLocation = getSafeDropLocation(block, !info.hasDropTable());
/* for (ItemStack drop : called.getDrops())
* apply triggers, add experience info to the event so the other events if (drop.getType() != Material.AIR && drop.getAmount() > 0)
* can give exp to other TOOLS and display HOLOGRAMS block.getWorld().dropItemNaturally(dropLocation, drop);
*/ }
if (info.hasTriggers()) {
PlayerData playerData = PlayerData.get(player);
info.getTriggers().forEach(trigger -> {
if(!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger)
trigger.apply(playerData);
});
if(!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, .5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()), player);
}
/*
* apply drop tables
*/
if (info.hasDropTable()) {
Location dropLocation = getSafeDropLocation(block, !info.hasDropTable());
for (ItemStack drop : called.getDrops())
if (drop.getType() != Material.AIR && drop.getAmount() > 0)
block.getWorld().dropItemNaturally(dropLocation, drop);
} }
/* /*