-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMagicBrushReward.java
50 lines (43 loc) · 1.68 KB
/
MagicBrushReward.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 me.pikamug.quests.module.BukkitCustomReward;
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 MagicBrushReward 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 MagicBrushReward() {
this.setName("Magic Brush");
this.setAuthor("NathanWolf");
this.setDisplay("Material Brush");
this.addStringPrompt("Brush", "The key name of the Magic material brush to give to the player.", null);
}
@Override
public void giveReward(UUID uuid, Map<String, Object> stringObjectMap) {
Player player = Bukkit.getPlayer(uuid);
MagicAPI api = getAPI(player.getServer());
String brushKey = (String)stringObjectMap.get("Brush");
if (brushKey != null) {
ItemStack item = api.createBrushItem(brushKey);
if (item != null) {
api.giveItemToPlayer(player, item);
} else {
Bukkit.getLogger().warning("Invalid brush given as Quests reward: " + brushKey);
}
}
}
}