use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.
the class EntityController method onItemSpawn.
@EventHandler(priority = EventPriority.LOWEST)
public void onItemSpawn(ItemSpawnEvent event) {
if (disableItemSpawn || com.elmakers.mine.bukkit.block.BlockData.undoing) {
event.setCancelled(true);
return;
}
Item itemEntity = event.getEntity();
ItemStack spawnedItem = itemEntity.getItemStack();
Block block = itemEntity.getLocation().getBlock();
BlockData undoData = com.elmakers.mine.bukkit.block.UndoList.getBlockData(block.getLocation());
boolean isBreaking = block.getType() != Material.AIR;
if (!isBreaking) {
MaterialSet doubleAttachables = controller.getMaterialSetManager().getMaterialSetEmpty("attachable_double");
isBreaking = doubleAttachables.testItem(spawnedItem);
}
if (undoData != null && isBreaking) {
// So we can catch this as a one-time event, for blocks we have recorded.
if (undoData.getMaterial() != Material.AIR) {
UndoList undoList = undoData.getUndoList();
if (undoList != null) {
undoList.add(block);
} else {
controller.getLogger().warning("Block broken into item under undo at " + block + ", but no undo list was assigned");
}
event.setCancelled(true);
return;
}
// If this was a block we built magically, don't drop items if the item being dropped
// matches the block type. This is messy, but avoid players losing all their items
// when suffocating inside a Blob
Collection<ItemStack> drops = block.getDrops();
if (drops != null) {
for (ItemStack drop : drops) {
if (drop.getType() == spawnedItem.getType()) {
com.elmakers.mine.bukkit.block.UndoList.commit(undoData);
event.setCancelled(true);
return;
}
}
}
}
if (Wand.isSkill(spawnedItem)) {
event.setCancelled(true);
return;
}
if (Wand.isWand(spawnedItem)) {
boolean invulnerable = controller.getWandProperty(spawnedItem, "invulnerable", false);
if (invulnerable) {
CompatibilityUtils.setInvulnerable(event.getEntity());
}
boolean trackWand = controller.getWandProperty(spawnedItem, "track", false);
if (trackWand) {
Wand wand = controller.getWand(spawnedItem);
controller.addLostWand(wand, event.getEntity().getLocation());
}
} else {
// registerEntityForUndo(event.getEntity());
if (ageDroppedItems > 0) {
int ticks = ageDroppedItems * 20 / 1000;
Item item = event.getEntity();
CompatibilityUtils.ageItem(item, ticks);
}
}
}
use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.
the class BlockSpell method areAnyDestructible.
public boolean areAnyDestructible(Block block) {
if (isIndestructible(block))
return false;
if (!checkDestructible)
return true;
if (targetBreakables > 0 && currentCast.isBreakable(block))
return true;
MaterialSet allDestructible = destructible;
if (allDestructible == null) {
allDestructible = controller.getDestructibleMaterialSet();
}
if (allDestructible == null) {
return true;
}
if (allDestructible.testBlock(block))
return true;
com.elmakers.mine.bukkit.api.block.BlockData blockData = UndoList.getBlockData(block.getLocation());
if (blockData == null || !blockData.containsAny(allDestructible)) {
return false;
}
return true;
}
use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.
the class AnimateSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
if (parameters.getString("animate", null) != null) {
return super.onCast(parameters);
}
final Block targetBlock = getTargetBlock();
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
int seedRadius = parameters.getInt("seed_radius", 0);
MaterialAndData targetMaterial = new MaterialAndData(targetBlock);
List<String> materials = ConfigurationUtils.getStringList(parameters, "materials");
if (seedRadius > 0 && materials != null && !materials.isEmpty()) {
targetMaterial = new MaterialAndData(RandomUtils.getRandom(materials));
} else if (parameters.contains("material")) {
targetMaterial = ConfigurationUtils.getMaterialAndData(parameters, "material", targetMaterial);
if (targetMaterial.isValid()) {
addDestructible(targetMaterial);
}
}
if (!mage.isSuperPowered() && seedRadius == 0) {
MaterialSetManager materialSets = controller.getMaterialSetManager();
MaterialSet restricted = materialSets.getMaterialSet("restricted");
if (restricted != null && restricted.testMaterialAndData(targetMaterial)) {
return SpellResult.FAIL;
}
if (parameters.contains("restricted")) {
String customRestricted = parameters.getString("restricted");
if (customRestricted != null && !customRestricted.equals("restricted")) {
restricted = materialSets.fromConfigEmpty(customRestricted);
if (restricted.testMaterialAndData(targetMaterial)) {
return SpellResult.FAIL;
}
}
}
}
if (!isDestructible(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
registerForUndo(targetBlock);
if (seedRadius > 0) {
for (int dx = -seedRadius; dx < seedRadius; dx++) {
for (int dz = -seedRadius; dz < seedRadius; dz++) {
for (int dy = -seedRadius; dy < seedRadius; dy++) {
Block seedBlock = targetBlock.getRelative(dx, dy, dz);
if (isDestructible(seedBlock)) {
registerForUndo(seedBlock);
targetMaterial.modify(seedBlock);
}
}
}
}
}
// Look for randomized levels
int level = 0;
if (parameters.contains("level")) {
level = parameters.getInt("level", level);
} else if (levelWeights != null) {
level = RandomUtils.weightedRandom(levelWeights);
}
boolean simCheckDestructible = parameters.getBoolean("sim_check_destructible", true);
simCheckDestructible = parameters.getBoolean("scd", simCheckDestructible);
final ConfigurationSection automataParameters = new MemoryConfiguration();
automataParameters.set("target", "self");
automataParameters.set("cooldown", 0);
automataParameters.set("m", targetMaterial.getKey());
automataParameters.set("cd", (simCheckDestructible ? true : false));
automataParameters.set("level", level);
String automataName = parameters.getString("name", "Automata");
Messages messages = controller.getMessages();
String automataType = parameters.getString("message_type", "evil");
List<String> prefixes = messages.getAll("automata." + automataType + ".prefixes");
List<String> suffixes = messages.getAll("automata." + automataType + ".suffixes");
automataName = prefixes.get(random.nextInt(prefixes.size())) + " " + automataName + " " + suffixes.get(random.nextInt(suffixes.size()));
if (level > 1) {
automataName += " " + escapeLevel(messages, "automata.level", level);
}
String message = getMessage("cast_broadcast").replace("$name", automataName);
if (message.length() > 0) {
controller.sendToMages(message, targetBlock.getLocation());
}
automataParameters.set("animate", automataName);
String automataId = UUID.randomUUID().toString();
final Mage mage = controller.getAutomaton(automataId, automataName);
mage.setLocation(targetBlock.getLocation());
mage.setQuiet(true);
mage.addTag(getKey());
final Spell spell = mage.getSpell(getKey());
Bukkit.getScheduler().runTaskLater(controller.getPlugin(), new Runnable() {
@Override
public void run() {
spell.cast(automataParameters);
}
}, 1);
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.
the class SimpleMaterialSetManager method getMaterialSet.
@Override
public MaterialSet getMaterialSet(String name, MaterialSet fallback) {
checkNotNull(fallback, "fallback");
MaterialSet set = getMaterialSet(name);
return set != null ? set : fallback;
}
use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.
the class SimpleMaterialSetManager method fromConfig.
@Nullable
@Override
public MaterialSet fromConfig(String name) {
if (name == null || name.isEmpty()) {
return null;
}
MaterialSet materials = materialSets.get(name);
if (materials == null) {
materials = createMaterialSetFromString(name);
materialSets.put(name, materials);
}
return materials;
}
Aggregations