use of org.bukkit.Material in project MagicPlugin by elBukkit.
the class FamiliarSpell method onCast.
@SuppressWarnings("deprecation")
@Override
public SpellResult onCast(ConfigurationSection parameters) {
spawnCount = 0;
Target target = getTarget();
if (!target.hasTarget()) {
return SpellResult.NO_TARGET;
}
Block originalTarget = target.getBlock();
Block targetBlock = originalTarget;
LivingEntity targetEntity = null;
boolean track = parameters.getBoolean("track", true);
boolean loot = parameters.getBoolean("loot", false);
boolean setTarget = parameters.getBoolean("set_target", true);
double spawnRange = parameters.getInt("spawn_range", 0);
String entityName = parameters.getString("name", "");
if (hasFamiliar() && track) {
// Dispel familiars if you target them and cast
boolean isFamiliar = target.hasEntity() && isFamiliar(target.getEntity());
if (isFamiliar) {
checkListener();
releaseFamiliar(target.getEntity());
return SpellResult.DEACTIVATE;
}
releaseFamiliars();
}
if (target.hasEntity()) {
targetBlock = targetBlock.getRelative(BlockFace.SOUTH);
Entity e = target.getEntity();
if (e instanceof LivingEntity) {
targetEntity = (LivingEntity) e;
}
}
targetBlock = targetBlock.getRelative(BlockFace.UP);
Location centerLoc = targetBlock.getLocation();
Location caster = getLocation();
if (spawnRange > 0) {
double distanceSquared = targetBlock.getLocation().distanceSquared(caster);
if (spawnRange * spawnRange < distanceSquared) {
Vector direction = caster.getDirection().normalize().multiply(spawnRange);
centerLoc = caster.clone().add(direction);
for (int i = 0; i < spawnRange; i++) {
Material blockType = centerLoc.getBlock().getType();
if (blockType == Material.AIR || blockType == Material.WATER || blockType != Material.STATIONARY_WATER) {
break;
}
centerLoc = centerLoc.add(0, 1, 0);
}
}
}
EntityType famType = null;
int famCount = parameters.getInt("count", 1);
String famTypeName = parameters.getString("type", null);
if (famTypeName != null && !famTypeName.isEmpty()) {
try {
famType = EntityType.valueOf(famTypeName.toUpperCase());
} catch (Throwable ex) {
sendMessage("Unknown entity type: " + famTypeName);
return SpellResult.FAIL;
}
}
if (originalTarget.getType() == Material.WATER || originalTarget.getType() == Material.STATIONARY_WATER) {
famType = EntityType.SQUID;
}
boolean spawnBaby = parameters.getBoolean("baby", false);
List<LivingEntity> newFamiliars = new ArrayList<>();
for (int i = 0; i < famCount; i++) {
EntityType entityType = famType;
if (entityType == null) {
String randomType = RandomUtils.weightedRandom(entityTypeProbability);
try {
entityType = EntityType.fromName(randomType);
} catch (Throwable ex) {
sendMessage("Unknown entity type: " + randomType);
return SpellResult.FAIL;
}
}
if (parameters.contains("reason")) {
String reasonText = parameters.getString("reason").toUpperCase();
try {
spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
} catch (Exception ex) {
sendMessage("Unknown spawn reason: " + reasonText);
return SpellResult.FAIL;
}
}
final Location targetLoc = centerLoc.clone();
if (famCount > 1) {
targetLoc.setX(targetLoc.getX() + rand.nextInt(2 * famCount) - famCount);
targetLoc.setZ(targetLoc.getZ() + rand.nextInt(2 * famCount) - famCount);
}
targetLoc.setPitch(caster.getPitch());
targetLoc.setYaw(caster.getYaw());
if (entityType != null) {
final LivingEntity entity = spawnFamiliar(targetLoc, entityType, targetBlock.getLocation(), targetEntity, setTarget);
if (entity != null) {
if (entityName != null && !entityName.isEmpty()) {
entity.setCustomName(entityName);
}
if (!loot) {
entity.setMetadata("nodrops", new FixedMetadataValue(mage.getController().getPlugin(), true));
}
if (spawnBaby && entity instanceof Ageable) {
Ageable ageable = (Ageable) entity;
ageable.setBaby();
}
entity.teleport(targetLoc);
newFamiliars.add(entity);
spawnCount++;
registerForUndo(entity);
}
}
}
registerForUndo();
if (track) {
setFamiliars(newFamiliars);
checkListener();
}
return SpellResult.CAST;
}
use of org.bukkit.Material in project MagicPlugin by elBukkit.
the class AlterSpell method adjust.
protected void adjust(Block block, byte dataValue, boolean recursive, int recurseDistance, int rDepth) {
registerForUndo(block);
try {
block.setData(dataValue);
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Failed to alter block state: " + ex.getMessage());
}
if (recursive && rDepth < recurseDistance) {
Material targetMaterial = block.getType();
tryAdjust(block.getRelative(BlockFace.NORTH), dataValue, targetMaterial, recurseDistance, rDepth + 1);
tryAdjust(block.getRelative(BlockFace.WEST), dataValue, targetMaterial, recurseDistance, rDepth + 1);
tryAdjust(block.getRelative(BlockFace.SOUTH), dataValue, targetMaterial, recurseDistance, rDepth + 1);
tryAdjust(block.getRelative(BlockFace.EAST), dataValue, targetMaterial, recurseDistance, rDepth + 1);
tryAdjust(block.getRelative(BlockFace.UP), dataValue, targetMaterial, recurseDistance, rDepth + 1);
tryAdjust(block.getRelative(BlockFace.DOWN), dataValue, targetMaterial, recurseDistance, rDepth + 1);
}
}
use of org.bukkit.Material in project MagicPlugin by elBukkit.
the class MagicTraitCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
if (!sender.hasPermission("Magic.commands.mtrait"))
return options;
String lastParameter = "";
if (args.length > 1) {
lastParameter = args[args.length - 2];
}
if (lastParameter.equalsIgnoreCase("spell")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, "Magic.cast.", spell.getKey());
}
} else if (lastParameter.equalsIgnoreCase("parameters")) {
options.addAll(Arrays.asList(BaseSpell.COMMON_PARAMETERS));
} else if (lastParameter.equalsIgnoreCase("hat")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
options.add(spell.getKey());
}
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
options.add(wandKey);
}
for (Material material : Material.values()) {
options.add(material.name().toLowerCase());
}
Collection<String> allItems = api.getController().getItemKeys();
for (String itemKey : allItems) {
options.add(itemKey);
}
} else if (lastParameter.equalsIgnoreCase("cost")) {
options.addAll(Arrays.asList(BaseSpell.EXAMPLE_SIZES));
} else if (lastParameter.equalsIgnoreCase("caster") || lastParameter.equalsIgnoreCase("invisible") || lastParameter.equalsIgnoreCase("target_player") || lastParameter.equalsIgnoreCase("message_player")) {
options.addAll(Arrays.asList(BaseSpell.EXAMPLE_BOOLEANS));
} else {
options.add("spell");
options.add("parameter");
options.add("caster");
options.add("target_player");
options.add("message_player");
options.add("cost");
options.add("permission");
options.add("invisible");
options.add("hat");
options.add("command");
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, "Magic.cast.", spell.getKey());
}
}
return options;
}
use of org.bukkit.Material in project MagicPlugin by elBukkit.
the class SpellsCommandExecutor method listSpells.
public void listSpells(CommandSender sender, int pageNumber, String category) {
if (category != null) {
listSpellsByCategory(sender, category);
return;
}
Player player = sender instanceof Player ? (Player) sender : null;
Collection<SpellTemplate> spellVariants = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
int spellCount = 0;
for (SpellTemplate spell : spellVariants) {
if (player != null && !spell.hasCastPermission(player)) {
continue;
}
if (spell.getCategory() == null)
continue;
spellCount++;
}
// Kinda hacky internals-reaching
Collection<SpellCategory> allCategories = api.getController().getCategories();
List<SpellCategory> sortedGroups = new ArrayList<>(allCategories);
Collections.sort(sortedGroups);
int maxLines = -1;
if (pageNumber >= 0) {
maxLines = 5;
int maxPages = spellCount / maxLines + 1;
if (pageNumber > maxPages) {
pageNumber = maxPages;
}
String message = api.getMessages().get("general.spell_list_page");
message = message.replace("$count", Integer.toString(spellCount));
message = message.replace("$pages", Integer.toString(maxPages));
message = message.replace("$page", Integer.toString(pageNumber));
sender.sendMessage(message);
} else {
String message = api.getMessages().get("general.spell_list");
message = message.replace("$count", Integer.toString(spellCount));
sender.sendMessage(message);
}
int currentPage = 1;
int lineCount = 0;
int printedCount = 0;
for (SpellCategory group : sortedGroups) {
if (printedCount > maxLines && maxLines > 0)
break;
boolean isFirst = true;
Collection<SpellTemplate> spells = group.getSpells();
for (SpellTemplate spell : spells) {
if (printedCount > maxLines && maxLines > 0)
break;
if (!spell.hasCastPermission(sender))
continue;
if (currentPage == pageNumber || maxLines < 0) {
if (isFirst) {
sender.sendMessage(group.getName() + ":");
isFirst = false;
}
String name = spell.getName();
String description = spell.getDescription();
if (!name.equals(spell.getKey())) {
description = name + " : " + description;
}
MaterialAndData spellIcon = spell.getIcon();
Material material = spellIcon == null ? null : spellIcon.getMaterial();
String icon = material == null ? "None" : material.name().toLowerCase();
sender.sendMessage(ChatColor.AQUA + spell.getKey() + ChatColor.BLUE + " [" + icon + "] : " + ChatColor.YELLOW + description);
printedCount++;
}
lineCount++;
if (lineCount == maxLines) {
lineCount = 0;
currentPage++;
}
}
}
}
use of org.bukkit.Material in project MagicPlugin by elBukkit.
the class RecurseAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
checker = parameters.getBoolean("checkered", false);
replace = parameters.getBoolean("replace", false);
recursionDepth = parameters.getInt("size", 32);
recursionDepth = parameters.getInt("depth", recursionDepth);
if (replace) {
if (replaceable == null) {
replaceable = new HashSet<>();
}
Block targetBlock = context.getTargetBlock();
replaceable.clear();
if (targetBlock == null) {
return;
}
MaterialAndData targetMaterialAndData = new MaterialAndData(targetBlock);
if (targetMaterialAndData.isValid()) {
replaceable.add(targetMaterialAndData);
}
Material targetMaterial = targetBlock.getType();
if (parameters.getBoolean("auto_water", true)) {
if (targetMaterial == Material.STATIONARY_WATER || targetMaterial == Material.WATER) {
for (byte i = 0; i < 15; i++) {
replaceable.add(new MaterialAndData(Material.STATIONARY_WATER, i));
replaceable.add(new MaterialAndData(Material.WATER, i));
}
}
}
if (parameters.getBoolean("auto_lava", true)) {
if (targetMaterial == Material.STATIONARY_LAVA || targetMaterial == Material.LAVA) {
for (byte i = 0; i < 15; i++) {
replaceable.add(new MaterialAndData(Material.STATIONARY_LAVA, i));
replaceable.add(new MaterialAndData(Material.LAVA, i));
}
}
}
if (parameters.getBoolean("auto_snow", true)) {
if (targetMaterial == Material.SNOW) {
for (byte i = 0; i < 15; i++) {
replaceable.add(new MaterialAndData(Material.SNOW, i));
}
}
}
} else {
replaceable = null;
}
}
Aggregations