use of com.elmakers.mine.bukkit.world.BlockResult in project MagicPlugin by elBukkit.
the class MagicBlockHandler method handleBlock.
public BlockResult handleBlock(Block block, Player player) {
Random random = getRandom(block.getWorld());
for (BlockRule blockRule : globalBlockRules) {
BlockResult result = blockRule.handle(block, random, player);
if (result != BlockResult.SKIP) {
return result;
}
}
List<BlockRule> rules = blockRules.get(block.getType());
if (rules != null) {
for (BlockRule blockRule : rules) {
BlockResult result = blockRule.handle(block, random, player);
if (result != BlockResult.SKIP) {
return result;
}
}
}
return BlockResult.SKIP;
}
use of com.elmakers.mine.bukkit.world.BlockResult in project MagicPlugin by elBukkit.
the class MagicBlockRule method onHandle.
@Override
@Nonnull
public BlockResult onHandle(Block block, Random random, Player cause) {
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) {
}
Mage mage = controller.getMage(cause);
Location location = block.getLocation();
MagicBlock magicBlock = controller.addMagicBlock(location, templateKey, mage.getId(), mage.getName(), parameters);
String message = " magic block: " + templateKey + " at " + location.getWorld().getName() + "," + location.toVector();
if (magicBlock == null) {
message = "Failed to create" + message;
} else {
message = "Created" + message;
}
controller.info(message);
return magicBlock == null ? BlockResult.SKIP : BlockResult.REMOVE_DROPS;
}
use of com.elmakers.mine.bukkit.world.BlockResult in project MagicPlugin by elBukkit.
the class WorldPlayerListener method onBlockPlace.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
MagicWorld magicWorld = controller.getWorld(block.getWorld().getName());
if (magicWorld == null)
return;
BlockResult result = magicWorld.processBlockPlace(block, event.getPlayer());
if (result == BlockResult.CANCEL) {
event.setCancelled(true);
}
}
use of com.elmakers.mine.bukkit.world.BlockResult in project MagicPlugin by elBukkit.
the class BaseBlockPopulator method populate.
@Override
public void populate(World world, Random random, Chunk chunk) {
for (int x = 0; x <= 15; x++) {
for (int z = 0; z <= 15; z++) {
for (int y = minY; y <= maxY; y++) {
Block block = chunk.getBlock(x, y, z);
if (y > maxAirY && block.getType() == Material.AIR) {
break;
}
if (biomes != null && !biomes.contains(block.getBiome()))
continue;
if (notBiomes != null && notBiomes.contains(block.getBiome()))
continue;
long now = System.currentTimeMillis();
if (cooldown > 0 && now < lastPopulate + cooldown)
continue;
BlockResult result = populate(block, random);
if (result != BlockResult.SKIP) {
lastPopulate = now;
}
}
}
}
}
use of com.elmakers.mine.bukkit.world.BlockResult in project MagicPlugin by elBukkit.
the class CastRule method onHandle.
@Override
@Nonnull
public BlockResult onHandle(Block block, Random random, Player cause) {
String[] standardParameters = { "tworld", block.getLocation().getWorld().getName(), "tx", Integer.toString(block.getLocation().getBlockX()), "ty", Integer.toString(block.getLocation().getBlockY()), "tz", Integer.toString(block.getLocation().getBlockZ()), "quiet", "true" };
if (spells == null) {
spells = new ArrayList<>();
}
if (spellProbability != null) {
CastSpell spell = RandomUtils.weightedRandom(spellProbability);
spells.clear();
spells.add(spell);
}
Mage mage = controller.getMage(cause);
boolean casted = false;
for (CastSpell castSpell : spells) {
if (castSpell.isEmpty()) {
BlockResult result = castSpell.getBlockResult();
if (result != BlockResult.SKIP) {
return result;
}
continue;
}
Spell spell = mage.getSpell(castSpell.getName());
if (spell == null)
continue;
String[] fullParameters = new String[castSpell.getParameters().length + standardParameters.length];
for (int index = 0; index < standardParameters.length; index++) {
fullParameters[index] = standardParameters[index];
}
for (int index = 0; index < castSpell.getParameters().length; index++) {
fullParameters[index + standardParameters.length] = castSpell.getParameters()[index];
}
casted = spell.cast(fullParameters) || casted;
}
return casted ? BlockResult.REPLACED_DROPS : BlockResult.REMOVE_DROPS;
}
Aggregations