-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMagicSpellReward.java
69 lines (61 loc) · 2.6 KB
/
MagicSpellReward.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.elmakers.mine.bukkit.magicquests;
import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.MageClass;
import com.elmakers.mine.bukkit.api.magic.MagicAPI;
import me.pikamug.quests.module.BukkitCustomReward;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import java.util.Map;
import java.util.UUID;
public class MagicSpellReward extends BukkitCustomReward {
// This boilerplate cannot be abstracted due to the class-scanning that Quests does
private static MagicAPI api;
protected static MagicAPI getAPI(Server server) {
if (api == null) {
Plugin magicPlugin = server.getPluginManager().getPlugin("Magic");
if (magicPlugin != null && magicPlugin instanceof MagicAPI) {
api = (MagicAPI)magicPlugin;
}
}
return api;
}
public MagicSpellReward() {
this.setName("Magic Spell");
this.setAuthor("NathanWolf");
this.setDisplay("Spell");
this.addStringPrompt("Spell", "The KEY name of the Magic spell to give to the player.", null);
this.addStringPrompt("Class", "The KEY name of the class (or a list of classes) to apply the spell to. If not set will be given to the player as an item.", null);
}
@Override
public void giveReward(UUID uuid, Map<String, Object> stringObjectMap) {
Player player = Bukkit.getPlayer(uuid);
MagicAPI api = getAPI(player.getServer());
String spellKey = (String)stringObjectMap.get("Spell");
String classKeyList = (String)stringObjectMap.get("Class");
if (spellKey != null) {
if (classKeyList != null) {
Mage mage = api.getController().getMage(player);
String[] classKeys = StringUtils.split(classKeyList, ",");
for (String classKey : classKeys) {
if (mage != null) {
MageClass mageClass = mage.getClass(classKey);
if (mageClass != null) {
mageClass.addSpell(spellKey);
}
}
}
} else {
ItemStack item = api.createSpellItem(spellKey);
if (item != null) {
api.giveItemToPlayer(player, item);
} else {
Bukkit.getLogger().warning("Invalid spell given as Quests reward: " + spellKey);
}
}
}
}
}