Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.nisovin.magicspells.util.Angle;

/**
* Parser that parsers a {@link Angle} from two floats.
* Parser that parses an {@link Angle} from a float.
*
* @param <C> Command sender type
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@ public static ParserDescriptor<CommandSourceStack, Spell> ownedSpellParser() {
CommandSender sender = stack.getExecutor();

Optional<Spell> parsedValue = result.parsedValue();
if (parsedValue.isPresent()) {
Spell spell = parsedValue.get();

if (sender instanceof Player player) {
Spellbook spellbook = MagicSpells.getSpellbook(player);
if (spell.isHelperSpell() && !Perm.COMMAND_CAST_SELF_HELPER.has(player) || !spellbook.hasSpell(spell))
return ArgumentParseResult.failure(new GenericCommandException(MagicSpells.getUnknownSpellMessage()));
}

if (!spell.canCastByCommand())
return ArgumentParseResult.failure(new GenericCommandException("You cannot cast this spell using commands."));

if (spell.isRequiringCastItemOnCommand()) {
if (!(sender instanceof LivingEntity entity))
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));

EntityEquipment equipment = entity.getEquipment();
if (equipment == null)
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));

ItemStack item = equipment.getItemInMainHand();
if (!spell.isValidItemForCastCommand(item))
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
}
if (parsedValue.isEmpty()) return result;

Spell spell = parsedValue.get();

if (sender instanceof Player player) {
Spellbook spellbook = MagicSpells.getSpellbook(player);
if (spell.isHelperSpell() && !Perm.COMMAND_CAST_SELF_HELPER.has(player) || !spellbook.hasSpell(spell))
return ArgumentParseResult.failure(new GenericCommandException(MagicSpells.getUnknownSpellMessage()));
}

if (!spell.canCastByCommand())
return ArgumentParseResult.failure(new GenericCommandException("You cannot cast this spell using commands."));

if (spell.isRequiringCastItemOnCommand()) {
if (!(sender instanceof LivingEntity entity))
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));

EntityEquipment equipment = entity.getEquipment();
if (equipment == null)
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));

ItemStack item = equipment.getItemInMainHand();
if (!spell.isValidItemForCastCommand(item))
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
}

return result;
Expand Down