-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathRequirement.java
84 lines (71 loc) · 3.15 KB
/
PathRequirement.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.elmakers.mine.bukkit.magicquests;
import java.util.Map;
import java.util.UUID;
import me.pikamug.quests.module.BukkitCustomRequirement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.MageClass;
import com.elmakers.mine.bukkit.api.magic.MageController;
import com.elmakers.mine.bukkit.api.magic.MagicAPI;
import com.elmakers.mine.bukkit.api.magic.ProgressionPath;
import com.elmakers.mine.bukkit.api.wand.Wand;
public class PathRequirement extends BukkitCustomRequirement {
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 PathRequirement() {
this.setName("Rank up");
this.setAuthor("NathanWolf");
this.addStringPrompt("Wand", "A specific wand template to look for", "");
this.addStringPrompt("Class", "A specific class to look for", "");
this.addStringPrompt("Path", "What path the player must be on.", null);
}
@Override
public boolean testRequirement(UUID uuid, Map<String, Object> stringObjectMap) {
Player player = Bukkit.getPlayer(uuid);
MagicAPI api = getAPI(player.getServer());
String pathKey = (String)stringObjectMap.get("Path");
if (api == null || pathKey == null) return false;
MageController controller = api.getController();
Mage mage = controller.getRegisteredMage(player);
if (mage == null) return false;
ProgressionPath path = null;
// Look for a specific wand first
String baseTemplate = (String)stringObjectMap.get("Wand");
String baseClass = (String)stringObjectMap.get("Class");
if (baseTemplate != null && !baseTemplate.isEmpty()) {
Wand boundWand = mage.getBoundWand(baseTemplate);
if (boundWand != null) {
path = boundWand.getPath();
}
} else if (baseClass != null && !baseClass.isEmpty()) {
MageClass mageClass = mage.getClass(baseClass);
if (mageClass != null) {
path = mageClass.getPath();
}
} else {
path = mage.getActiveProperties().getPath();
}
boolean isDebug = mage.getDebugLevel() > 0;
if (path == null) {
if (isDebug) mage.sendDebugMessage(ChatColor.RED + "Has no " + ChatColor.YELLOW + baseTemplate + ChatColor.DARK_RED +" wand", 7);
return false;
}
boolean hasPath = path.hasPath(pathKey);
if (isDebug) mage.sendDebugMessage(ChatColor.BLUE + "Checking wand path " + ChatColor.GOLD + path.getKey() +
ChatColor.BLUE +" has path " + ChatColor.YELLOW + pathKey + "? " +
(hasPath ? ChatColor.GREEN + "Yes" : ChatColor.RED + "No"), 7);
return hasPath;
}
}