use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class BlockController method onEntityChangeBlockEvent.
@EventHandler(ignoreCancelled = true)
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
Entity entity = event.getEntity();
if (entity instanceof FallingBlock) {
EntityData entityData = controller.getMob(entity);
if (entityData != null && !entityData.isTransformable()) {
event.setCancelled(true);
return;
}
if (event.getTo() == Material.AIR) {
// Block is falling, register it
controller.registerFallingBlock(entity, event.getBlock());
} else {
// Block is landing, convert it
UndoList blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
if (blockList != null) {
com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
if (context != null && !context.hasBuildPermission(entity.getLocation().getBlock())) {
event.setCancelled(true);
} else {
Block block = event.getBlock();
blockList.convert(entity, block);
if (!blockList.getApplyPhysics()) {
FallingBlock falling = (FallingBlock) entity;
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
Material material = compatibilityUtils.getMaterial(falling);
String blockData = compatibilityUtils.getBlockData(falling);
if (blockData != null) {
compatibilityUtils.setBlockData(block, blockData);
} else {
byte data = CompatibilityLib.getCompatibilityUtils().getLegacyBlockData(falling);
CompatibilityLib.getDeprecatedUtils().setTypeAndData(block, material, data, false);
}
entity.remove();
event.setCancelled(true);
}
}
}
}
}
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class ShrinkEntityAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
MageController controller = context.getController();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
if (elementalSize < 0.1) {
return super.perform(context);
}
elementalSize /= 2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
boolean alreadyDead = li.isDead() || li.getHealth() <= 0;
String itemName = CompatibilityLib.getDeprecatedUtils().getDisplayName(li) + " Head";
EntityType replaceType = null;
boolean handled = true;
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
if (li instanceof Player) {
super.perform(context);
if (li.isDead() && !alreadyDead && dropSkull) {
dropHead(context, targetEntity, itemName);
}
} else if (li.getType() == EntityType.GIANT) {
replaceType = EntityType.ZOMBIE;
} else if (li instanceof Ageable && ((Ageable) li).isAdult()) {
context.registerModified(li);
((Ageable) li).setBaby();
} else if (li instanceof Zombie && compatibilityUtils.isAdult((Zombie) li)) {
context.registerModified(li);
compatibilityUtils.setBaby((Zombie) li);
} else if (li instanceof Slime && ((Slime) li).getSize() > 1) {
context.registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() - 1);
} else if (li instanceof Slime && ((Slime) li).getSize() > 1) {
context.registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() - 1);
} else if (li.getType().name().equals("WITHER_SKELETON") && skeletons) {
replaceType = EntityType.SKELETON;
} else if (li.getType().name().equals("PHANTOM")) {
int size = compatibilityUtils.getPhantomSize(li);
if (size > 1) {
compatibilityUtils.setPhantomSize(li, size - 1);
} else {
handled = false;
}
} else {
handled = false;
}
if (!handled) {
super.perform(context);
if ((li.isDead() || li.getHealth() == 0) && !alreadyDead && dropSkull) {
dropHead(context, targetEntity, itemName);
}
}
if (replaceType != null) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
context.registerModified(li);
Entity replacement = controller.replaceMob(li, new EntityData(controller, replaceType), true, CreatureSpawnEvent.SpawnReason.CUSTOM);
if (replacement == null) {
return SpellResult.FAIL;
}
if (replacement instanceof Zombie) {
compatibilityUtils.setAdult((Zombie) replacement);
}
context.registerForUndo(replacement);
if (spawnedList != null) {
spawnedList.add(replacement);
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class PowerBlockAction method perform.
@Override
public SpellResult perform(CastContext context) {
Block block = context.getTargetBlock();
if (!context.hasBuildPermission(block)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!context.isDestructible(block)) {
return SpellResult.NO_TARGET;
}
context.getUndoList().setApplyPhysics(true);
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
if (compatibilityUtils.canToggleBlockPower(block)) {
context.registerForUndo(block);
compatibilityUtils.toggleBlockPower(block);
} else {
Material material = block.getType();
BlockState blockState = block.getState();
MageController controller = context.getController();
boolean updateBlockState = false;
if (material == Material.REDSTONE_BLOCK) {
context.registerForUndo(block);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material);
controller.getRedstoneReplacement().modify(block, applyPhysics);
} else if (material == Material.TNT) {
context.registerForUndo(block);
block.setType(Material.AIR);
// Kaboomy time!
context.registerForUndo(block.getLocation().getWorld().spawnEntity(block.getLocation(), EntityType.PRIMED_TNT));
}
if (updateBlockState) {
blockState.update();
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class EntityAnimationAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity target = context.getTargetEntity();
if (!(target instanceof LivingEntity)) {
return SpellResult.LIVING_ENTITY_REQUIRED;
}
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
LivingEntity targetEntity = (LivingEntity) target;
switch(animationType) {
case SWING_MAIN_HAND:
compatibilityUtils.swingMainHand(targetEntity);
break;
case SWING_OFF_HAND:
compatibilityUtils.swingOffhand(targetEntity);
break;
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class EquipAction method initialize.
@Override
public void initialize(Spell spell, ConfigurationSection parameters) {
super.initialize(spell, parameters);
if (parameters.contains("enchantments")) {
enchantments = new HashMap<>();
ConfigurationSection enchantConfig = ConfigurationUtils.getConfigurationSection(parameters, "enchantments");
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
Collection<String> enchantKeys = enchantConfig.getKeys(false);
for (String enchantKey : enchantKeys) {
Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
if (enchantment == null) {
spell.getController().getLogger().warning("Invalid enchantment in equip action: " + enchantKey);
} else {
enchantments.put(enchantment, enchantConfig.getInt(enchantKey));
}
}
}
}
Aggregations