-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
HeroesPlayerNPCExtension.java
73 lines (62 loc) · 2.47 KB
/
HeroesPlayerNPCExtension.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
package com.morphanone.depenizenbukkit.extensions.heroes;
import com.herocraftonline.heroes.Heroes;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import com.morphanone.depenizenbukkit.extensions.dObjectExtension;
import com.morphanone.depenizenbukkit.objects.heroes.HeroesHero;
import com.morphanone.depenizenbukkit.support.Support;
import com.morphanone.depenizenbukkit.support.plugins.HeroesSupport;
import org.bukkit.entity.Player;
public class HeroesPlayerNPCExtension extends dObjectExtension {
public static boolean describes(dObject object) {
return (object instanceof dPlayer && ((dPlayer) object).isOnline())
|| (object instanceof dNPC && ((dNPC) object).isSpawned()
&& ((dNPC) object).getEntity() instanceof Player);
}
public static HeroesPlayerNPCExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new HeroesPlayerNPCExtension(object);
}
}
private HeroesPlayerNPCExtension(dObject object) {
if (object instanceof dPlayer) {
player = ((dPlayer) object).getPlayerEntity();
}
else if (object instanceof dNPC) {
player = (Player) ((dNPC) object).getEntity();
}
}
Player player = null;
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <p@player.heroes>
// @returns HeroesHero
// @description
// Returns this player as a HeroesHero. This is designed
// to allow <p@player.heroes.some.extensions> for ease of use, and
// usually should not be used alone.
// @plugin Depenizen, Heroes
// -->
// <--[tag]
// @attribute <n@npc.heroes>
// @returns HeroesHero
// @description
// Returns a Player-type NPC as a HeroesHero. This is designed
// to allow <n@npc.heroes.some.extensions> for ease of use, and
// usually shouldn't be used alone.
// @plugin Depenizen, Heroes
// -->
if (attribute.startsWith("heroes")) {
Heroes heroes = Support.getPlugin(HeroesSupport.class);
return new HeroesHero(heroes.getCharacterManager().getHero(player))
.getAttribute(attribute.fulfill(1));
}
return null;
}
}