-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMagicUpgradeReward.java
50 lines (43 loc) · 1.68 KB
/
MagicUpgradeReward.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
package com.elmakers.mine.bukkit.magicquests;
import com.elmakers.mine.bukkit.api.magic.MagicAPI;
import com.elmakers.mine.bukkit.api.wand.Wand;
import me.pikamug.quests.module.BukkitCustomReward;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.Map;
import java.util.UUID;
public class MagicUpgradeReward 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 MagicUpgradeReward() {
this.setName("Magic Upgrade");
this.setAuthor("NathanWolf");
this.setDisplay("Wand Upgrade");
this.addStringPrompt("Wand", "The key name of the Magic wand or upgrade item to use.", null);
}
@Override
public void giveReward(UUID uuid, Map<String, Object> stringObjectMap) {
Player player = Bukkit.getPlayer(uuid);
MagicAPI api = getAPI(player.getServer());
String wandKey = (String)stringObjectMap.get("Wand");
if (wandKey != null) {
Wand wand = api.createUpgrade(wandKey);
if (wand != null) {
api.giveItemToPlayer(player, wand.getItem());
} else {
Bukkit.getLogger().warning("Invalid upgrade given as Quests reward: " + wandKey);
}
}
}
}