Skip to content

Commit 62a6324

Browse files
Merge pull request #1071 from TonytheMacaroni/cloud-commands
Cleanup parsers
2 parents 783842d + f49ffa7 commit 62a6324

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

core/src/main/java/com/nisovin/magicspells/commands/parsers/AngleParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.nisovin.magicspells.util.Angle;
1919

2020
/**
21-
* Parser that parsers a {@link Angle} from two floats.
21+
* Parser that parses an {@link Angle} from a float.
2222
*
2323
* @param <C> Command sender type
2424
*/

core/src/main/java/com/nisovin/magicspells/commands/parsers/OwnedSpellParser.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,30 @@ public static ParserDescriptor<CommandSourceStack, Spell> ownedSpellParser() {
4141
CommandSender sender = stack.getExecutor();
4242

4343
Optional<Spell> parsedValue = result.parsedValue();
44-
if (parsedValue.isPresent()) {
45-
Spell spell = parsedValue.get();
46-
47-
if (sender instanceof Player player) {
48-
Spellbook spellbook = MagicSpells.getSpellbook(player);
49-
if (spell.isHelperSpell() && !Perm.COMMAND_CAST_SELF_HELPER.has(player) || !spellbook.hasSpell(spell))
50-
return ArgumentParseResult.failure(new GenericCommandException(MagicSpells.getUnknownSpellMessage()));
51-
}
52-
53-
if (!spell.canCastByCommand())
54-
return ArgumentParseResult.failure(new GenericCommandException("You cannot cast this spell using commands."));
55-
56-
if (spell.isRequiringCastItemOnCommand()) {
57-
if (!(sender instanceof LivingEntity entity))
58-
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
59-
60-
EntityEquipment equipment = entity.getEquipment();
61-
if (equipment == null)
62-
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
63-
64-
ItemStack item = equipment.getItemInMainHand();
65-
if (!spell.isValidItemForCastCommand(item))
66-
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
67-
}
44+
if (parsedValue.isEmpty()) return result;
45+
46+
Spell spell = parsedValue.get();
47+
48+
if (sender instanceof Player player) {
49+
Spellbook spellbook = MagicSpells.getSpellbook(player);
50+
if (spell.isHelperSpell() && !Perm.COMMAND_CAST_SELF_HELPER.has(player) || !spellbook.hasSpell(spell))
51+
return ArgumentParseResult.failure(new GenericCommandException(MagicSpells.getUnknownSpellMessage()));
52+
}
53+
54+
if (!spell.canCastByCommand())
55+
return ArgumentParseResult.failure(new GenericCommandException("You cannot cast this spell using commands."));
56+
57+
if (spell.isRequiringCastItemOnCommand()) {
58+
if (!(sender instanceof LivingEntity entity))
59+
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
60+
61+
EntityEquipment equipment = entity.getEquipment();
62+
if (equipment == null)
63+
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
64+
65+
ItemStack item = equipment.getItemInMainHand();
66+
if (!spell.isValidItemForCastCommand(item))
67+
return ArgumentParseResult.failure(new GenericCommandException(spell.getStrWrongCastItem()));
6868
}
6969

7070
return result;

0 commit comments

Comments
 (0)