use of com.elmakers.mine.bukkit.world.BlockResult in project MagicPlugin by elBukkit.
the class MagicBlockPopulator method populate.
@Override
public BlockResult populate(Block block, Random random) {
if (replace != null && !replace.testBlock(block)) {
return BlockResult.SKIP;
}
String templateKey = RandomUtils.weightedRandom(templateProbability);
if (templateKey.equalsIgnoreCase("none")) {
return BlockResult.SKIP;
}
try {
BlockResult result = BlockResult.valueOf(templateKey.toUpperCase());
return result;
} catch (Exception ignore) {
}
Location location = block.getLocation();
MagicBlock automaton = controller.addMagicBlock(location, templateKey, null, null, parameters);
String message = " magic block: " + templateKey + " at " + location.getWorld().getName() + "," + location.toVector();
if (automaton == null) {
message = "Failed to create" + message;
} else {
message = "Created" + message;
}
controller.info(message);
return automaton == null ? BlockResult.SKIP : BlockResult.REMOVE_DROPS;
}
use of com.elmakers.mine.bukkit.world.BlockResult in project MagicPlugin by elBukkit.
the class WorldPlayerListener method onBlockBreak.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
MagicWorld magicWorld = controller.getWorld(block.getWorld().getName());
if (magicWorld == null)
return;
BlockResult result = magicWorld.processBlockBreak(block, event.getPlayer());
if (result == BlockResult.CANCEL) {
event.setCancelled(true);
}
if (result == BlockResult.REMOVE_DROPS) {
event.setCancelled(true);
block.setType(Material.AIR);
}
}
Aggregations