use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class DropAction method perform.
@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
Block block = context.getTargetBlock();
if (!context.hasBreakPermission(block)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!context.isDestructible(block)) {
return SpellResult.NO_TARGET;
}
// Don't allow dropping temporary blocks
UndoList blockUndoList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(block.getLocation());
if (blockUndoList != null && blockUndoList.isScheduled()) {
return SpellResult.NO_TARGET;
}
if (dropCount < 0 || drops.size() < dropCount) {
drops.addAll(block.getDrops());
} else if (falling) {
Location blockLocation = block.getLocation();
FallingBlock falling = block.getWorld().spawnFallingBlock(blockLocation, block.getType(), block.getData());
falling.setDropItem(false);
}
block.setType(Material.AIR);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class GrowEntityAction 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);
elementalSize *= 1.2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
context.registerModified(li);
((Ageable) li).setAdult();
} else if (li instanceof Zombie) {
context.registerModified(li);
Zombie zombie = (Zombie) li;
if (!zombie.isBaby()) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
Location targetLocation = li.getLocation();
li.remove();
Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
context.registerForUndo(giant);
if (spawnedList != null) {
spawnedList.add(giant);
}
} else {
((Zombie) li).setBaby(false);
}
} else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
context.registerModified(li);
((PigZombie) li).setBaby(false);
} else if (li instanceof Slime) {
context.registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() + 1);
} else if (li instanceof Skeleton && skeletons && ((Skeleton) li).getSkeletonType() == Skeleton.SkeletonType.NORMAL) {
context.registerModified(li);
Skeleton skeleton = (Skeleton) li;
skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
} else {
return SpellResult.NO_TARGET;
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class ActionBatch method finish.
@Override
public void finish() {
if (!finished) {
handler.cancel(context);
handler.finish(context);
context.finish();
// Shouldn't need this anymore
UndoList undoList = context.getUndoList();
if (undoList != null) {
undoList.setBatch(null);
}
finished = true;
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class ConfigurationMageDataStore method save.
public static void save(MageController controller, MageData mage, ConfigurationSection saveFile) {
saveFile.set("id", mage.getId());
saveFile.set("name", mage.getName());
saveFile.set("last_cast", mage.getLastCast());
saveFile.set("cooldown_expiration", mage.getCooldownExpiration());
saveFile.set("last_death_location", ConfigurationUtils.fromLocation(mage.getLastDeathLocation()));
Location location = mage.getLocation();
if (location != null) {
saveFile.set("location", ConfigurationUtils.fromLocation(location));
}
saveFile.set("destination_warp", mage.getDestinationWarp());
saveFile.set("fall_protection_count", mage.getFallProtectionCount());
saveFile.set("fall_protection", mage.getFallProtectionDuration());
BrushData brush = mage.getBrushData();
if (brush != null) {
ConfigurationSection brushNode = saveFile.createSection("brush");
try {
Location cloneSource = brush.getCloneLocation();
if (cloneSource != null) {
brushNode.set("clone_location", ConfigurationUtils.fromLocation(cloneSource));
}
Location cloneTarget = brush.getCloneTarget();
if (cloneTarget != null) {
brushNode.set("clone_target", ConfigurationUtils.fromLocation(cloneTarget));
}
Location materialTarget = brush.getMaterialTarget();
if (materialTarget != null) {
brushNode.set("material_target", ConfigurationUtils.fromLocation(materialTarget));
}
brushNode.set("map_id", brush.getMapId());
brushNode.set("material", ConfigurationUtils.fromMaterial(brush.getMaterial()));
brushNode.set("data", brush.getMaterialData());
brushNode.set("schematic", brush.getSchematicName());
brushNode.set("scale", brush.getScale());
brushNode.set("erase", brush.isFillWithAir());
} catch (Exception ex) {
controller.getLogger().warning("Failed to save brush data: " + ex.getMessage());
ex.printStackTrace();
}
}
UndoData undoData = mage.getUndoData();
if (undoData != null) {
List<Map<String, Object>> nodeList = new ArrayList<>();
List<UndoList> undoList = undoData.getBlockList();
for (UndoList list : undoList) {
MemoryConfiguration listNode = new MemoryConfiguration();
list.save(listNode);
nodeList.add(listNode.getValues(true));
}
saveFile.set("undo", nodeList);
}
ConfigurationSection spellNode = saveFile.createSection("spells");
Collection<SpellData> spellData = mage.getSpellData();
if (spellData != null) {
for (SpellData spell : spellData) {
ConfigurationSection node = spellNode.createSection(spell.getKey().getKey());
node.set("cast_count", spell.getCastCount());
node.set("last_cast", spell.getLastCast());
node.set("last_earn", spell.getLastEarn());
node.set("cooldown_expiration", spell.getCooldownExpiration());
node.set("active", spell.isActive() ? true : null);
ConfigurationSection extra = spell.getExtraData();
if (extra != null) {
ConfigurationUtils.addConfigurations(node, extra);
}
}
}
Map<String, ItemStack> boundWands = mage.getBoundWands();
if (boundWands != null && boundWands.size() > 0) {
ConfigurationSection wandSection = saveFile.createSection("wands");
for (Map.Entry<String, ItemStack> wandEntry : boundWands.entrySet()) {
String key = wandEntry.getKey();
if (key == null || key.isEmpty())
continue;
controller.serialize(wandSection, key, wandEntry.getValue());
}
}
Map<Integer, ItemStack> respawnArmor = mage.getRespawnArmor();
if (respawnArmor != null) {
ConfigurationSection armorSection = saveFile.createSection("respawn_armor");
for (Map.Entry<Integer, ItemStack> entry : respawnArmor.entrySet()) {
controller.serialize(armorSection, Integer.toString(entry.getKey()), entry.getValue());
}
}
Map<Integer, ItemStack> respawnInventory = mage.getRespawnInventory();
if (respawnInventory != null) {
ConfigurationSection inventorySection = saveFile.createSection("respawn_inventory");
for (Map.Entry<Integer, ItemStack> entry : respawnInventory.entrySet()) {
controller.serialize(inventorySection, Integer.toString(entry.getKey()), entry.getValue());
}
}
List<ItemStack> storedInventory = mage.getStoredInventory();
if (storedInventory != null) {
saveFile.set("inventory", storedInventory);
}
saveFile.set("experience", mage.getStoredExperience());
saveFile.set("level", mage.getStoredLevel());
saveFile.set("open_wand", mage.isOpenWand());
saveFile.set("gave_welcome_wand", mage.getGaveWelcomeWand());
ConfigurationSection extraData = mage.getExtraData();
if (extraData != null) {
ConfigurationSection dataSection = saveFile.createSection("data");
ConfigurationUtils.addConfigurations(dataSection, extraData);
}
ConfigurationSection properties = mage.getProperties();
if (properties != null) {
ConfigurationSection propertiesSection = saveFile.createSection("properties");
ConfigurationUtils.addConfigurations(propertiesSection, properties);
}
Map<String, ConfigurationSection> classProperties = mage.getClassProperties();
if (classProperties != null) {
ConfigurationSection classesSection = saveFile.createSection("classes");
for (Map.Entry<String, ConfigurationSection> entry : classProperties.entrySet()) {
ConfigurationSection classSection = classesSection.createSection(entry.getKey());
ConfigurationUtils.addConfigurations(classSection, entry.getValue());
}
}
saveFile.set("active_class", mage.getActiveClass());
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class GrowSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (!target.hasEntity()) {
return SpellResult.NO_TARGET;
}
Entity targetEntity = target.getEntity();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
elementalSize *= 1.2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
registerModified(li);
((Ageable) li).setAdult();
} else if (li instanceof Zombie) {
registerModified(li);
Zombie zombie = (Zombie) li;
if (!zombie.isBaby()) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
Location targetLocation = li.getLocation();
li.remove();
Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
registerForUndo(giant);
if (spawnedList != null) {
spawnedList.add(giant);
}
} else {
((Zombie) li).setBaby(false);
}
} else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
registerModified(li);
((PigZombie) li).setBaby(false);
} else if (li instanceof Slime) {
registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() + 1);
} else {
return SpellResult.NO_TARGET;
}
registerForUndo();
return SpellResult.CAST;
}
Aggregations