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
6 changes: 6 additions & 0 deletions core/src/main/java/com/nisovin/magicspells/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public abstract class Spell implements Comparable<Spell>, Listener {
protected String strWrongCastItem;
protected String strModifierFailed;
protected String strMissingReagents;
protected String strCantCastByCommand;

protected ModifierSet modifiers;
protected ModifierSet targetModifiers;
Expand Down Expand Up @@ -436,6 +437,7 @@ public Spell(MagicConfig config, String spellName) {
strWrongCastItem = config.getString(internalKey + "str-wrong-cast-item", strCantCast);
strModifierFailed = config.getString(internalKey + "str-modifier-failed", null);
strMissingReagents = config.getString(internalKey + "str-missing-reagents", MagicSpells.getMissingReagentsMessage());
strCantCastByCommand = config.getString(internalKey + "str-cant-cast-by-command", "You cannot cast this spell by commands.");
if (strXpAutoLearned != null) strXpAutoLearned = strXpAutoLearned.replace("%s", name);

tags = new HashSet<>(config.getStringList(internalKey + "tags", new ArrayList<>()));
Expand Down Expand Up @@ -2492,6 +2494,10 @@ public String getStrWrongCastItem() {
return strWrongCastItem;
}

public String getStrCantCastByCommand() {
return strCantCastByCommand;
}

public List<String> getPrecludes() {
return precludes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,21 +741,22 @@ public void onCastSelf(CommandIssuer issuer, String[] args) {
return;
}
// Player
if (sender instanceof Player) {
Player player = ((Player) sender).getPlayer();
if (player == null) return;
if (!spell.canCastByCommand()) {
MagicSpells.sendMessage(MagicSpells.getTextColor() + "You cannot cast this spell by commands.", player, null);
return;
}
if (sender instanceof Player player) {
if (spell.isHelperSpell() && !Perm.COMMAND_CAST_SELF_HELPER.has(player) || !MagicSpells.getSpellbook(player).hasSpell(spell)) {
MagicSpells.sendMessage(MagicSpells.getTextColor() + MagicSpells.getUnknownSpellMessage(), player, null);
return;
}

if (!spell.canCastByCommand()) {
MagicSpells.sendMessage(MagicSpells.getTextColor() + spell.getStrCantCastByCommand(), player, null);
return;
}

if (!spell.isValidItemForCastCommand(player.getInventory().getItemInMainHand())) {
MagicSpells.sendMessage(spell.getStrWrongCastItem(), player, null);
return;
}

spell.hardCast(new SpellData(player, power, spellArgs));
return;
}
Expand Down