Slightly improved where custom block drops spawn

This commit is contained in:
Indyuce 2020-03-19 13:29:36 +01:00
parent 17d99ace1b
commit df52b2c679
2 changed files with 38 additions and 29 deletions

View File

@ -67,7 +67,7 @@ public class BlockListener implements Listener {
return; return;
} }
if(!perms.canMine(getBlockName(block))) { if (!perms.canMine(getBlockName(block))) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player); MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -77,8 +77,8 @@ public class BlockListener implements Listener {
* remove vanilla drops if needed * remove vanilla drops if needed
*/ */
if (!info.hasVanillaDrops()) { if (!info.hasVanillaDrops()) {
event.setDropItems(false); //May not work event.setDropItems(false); // May not work
//event.setCancelled(true); // event.setCancelled(true);
event.getBlock().setType(Material.AIR); event.getBlock().setType(Material.AIR);
} }
@ -89,15 +89,22 @@ public class BlockListener implements Listener {
if (info.hasTriggers() && !block.hasMetadata("player_placed")) { if (info.hasTriggers() && !block.hasMetadata("player_placed")) {
PlayerData playerData = PlayerData.get(player); PlayerData playerData = PlayerData.get(player);
info.getTriggers().forEach(trigger -> trigger.apply(playerData)); info.getTriggers().forEach(trigger -> trigger.apply(playerData));
/**if (!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms()) /**
MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()).message(), player);*/ * if (!block.hasMetadata("player_placed") &&
* info.hasExperience() && MMOCore.plugin.hasHolograms())
* MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5,
* 1.5, .5),
* MMOCore.plugin.configManager.getSimpleMessage("exp-hologram",
* "exp", "" +
* called.getGainedExperience().getValue()).message(), player);
*/
} }
/* /*
* apply drop tables * apply drop tables
*/ */
if (info.hasDropTable()) { if (info.hasDropTable()) {
Location dropLocation = getSafeDropLocation(block, !info.hasDropTable()); Location dropLocation = getSafeDropLocation(block, true);
for (ItemStack drop : called.getDrops()) for (ItemStack drop : called.getDrops())
if (drop.getType() != Material.AIR && drop.getAmount() > 0) if (drop.getType() != Material.AIR && drop.getAmount() > 0)
block.getWorld().dropItemNaturally(dropLocation, drop); block.getWorld().dropItemNaturally(dropLocation, drop);
@ -107,7 +114,7 @@ public class BlockListener implements Listener {
* enable block regen. * enable block regen.
*/ */
if (info.hasRegen()) { if (info.hasRegen()) {
if(MMOLib.plugin.getVersion().isStrictlyHigher(1, 12)) if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 12))
MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(Bukkit.createBlockData(savedData), block.getLocation())); MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(Bukkit.createBlockData(savedData), block.getLocation()));
else else
MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(block.getLocation())); MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(block.getLocation()));
@ -116,10 +123,10 @@ public class BlockListener implements Listener {
} }
private String getBlockName(Block block) { private String getBlockName(Block block) {
if(MMOCore.plugin.isMILoaded()) if (MMOCore.plugin.isMILoaded())
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) { if (MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) {
CustomBlock cblock = CustomBlock.getFromData(block.getBlockData()); CustomBlock cblock = CustomBlock.getFromData(block.getBlockData());
if(cblock != null) if (cblock != null)
return "MICUSTOM_" + cblock.getId(); return "MICUSTOM_" + cblock.getId();
} }
@ -134,7 +141,8 @@ public class BlockListener implements Listener {
@EventHandler @EventHandler
public void c1(BlockPistonExtendEvent event) { public void c1(BlockPistonExtendEvent event) {
Block movedBlock = event.getBlock(); Block movedBlock = event.getBlock();
if(!movedBlock.hasMetadata("player_placed")) return; if (!movedBlock.hasMetadata("player_placed"))
return;
BlockFace direction = event.getDirection(); BlockFace direction = event.getDirection();
movedBlock = movedBlock.getRelative(direction, 2); movedBlock = movedBlock.getRelative(direction, 2);
@ -145,6 +153,7 @@ public class BlockListener implements Listener {
} }
} }
} }
@EventHandler @EventHandler
public void c2(BlockPistonRetractEvent event) { public void c2(BlockPistonRetractEvent event) {
BlockFace direction = event.getDirection(); BlockFace direction = event.getDirection();

View File

@ -124,7 +124,7 @@ public class CustomBlockManager extends MMOManager {
} }
public class BlockInfo { public class BlockInfo {
private Material block; private final Material block;
private final DropTable table; private final DropTable table;
private final boolean vanillaDrops; private final boolean vanillaDrops;
private final String headValue; private final String headValue;