├── .script
└── upload-javadoc.sh
├── .travis.yml
├── API
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── inventivetalent
│ │ │ └── npclib
│ │ │ ├── ArrayMaker.java
│ │ │ ├── ClassBuilder.java
│ │ │ ├── ClassGenerator.java
│ │ │ ├── INPCChannel.java
│ │ │ ├── INPCPlayerConnection.java
│ │ │ ├── NPCLib.java
│ │ │ ├── NPCType.java
│ │ │ ├── ObjectContainer.java
│ │ │ ├── ObjectConverter.java
│ │ │ ├── Reflection.java
│ │ │ ├── SuperSwitch.java
│ │ │ ├── ai
│ │ │ └── AIAbstract.java
│ │ │ ├── animation
│ │ │ └── Animation.java
│ │ │ ├── annotation
│ │ │ ├── ExtraMethod.java
│ │ │ ├── ExtraMethods.java
│ │ │ ├── NPC.java
│ │ │ └── NPCInfo.java
│ │ │ ├── entity
│ │ │ ├── EntityExperienceOrb.java
│ │ │ ├── EntityItem.java
│ │ │ ├── NPCEntity.java
│ │ │ └── living
│ │ │ │ ├── EntityArmorStand.java
│ │ │ │ ├── NPCEntityLiving.java
│ │ │ │ ├── human
│ │ │ │ ├── EntityPlayer.java
│ │ │ │ └── NPCEntityHuman.java
│ │ │ │ └── insentient
│ │ │ │ ├── EntityEnderDragon.java
│ │ │ │ ├── EntityPigZombie.java
│ │ │ │ ├── EntitySlime.java
│ │ │ │ ├── EntityZombie.java
│ │ │ │ ├── NPCEntityInsentient.java
│ │ │ │ ├── creature
│ │ │ │ ├── NPCEntityCreature.java
│ │ │ │ ├── ageable
│ │ │ │ │ ├── EntityVillager.java
│ │ │ │ │ ├── NPCEntityAgeable.java
│ │ │ │ │ └── animal
│ │ │ │ │ │ ├── EntityChicken.java
│ │ │ │ │ │ ├── EntityCow.java
│ │ │ │ │ │ ├── EntityHorse.java
│ │ │ │ │ │ ├── EntityLlama.java
│ │ │ │ │ │ ├── EntityMushroomCow.java
│ │ │ │ │ │ ├── EntityPig.java
│ │ │ │ │ │ ├── EntityPolarBear.java
│ │ │ │ │ │ ├── EntityRabbit.java
│ │ │ │ │ │ ├── EntitySheep.java
│ │ │ │ │ │ ├── NPCEntityAnimal.java
│ │ │ │ │ │ └── tameable
│ │ │ │ │ │ ├── EntityOcelot.java
│ │ │ │ │ │ ├── EntityWolf.java
│ │ │ │ │ │ └── NPCEntityTameable.java
│ │ │ │ ├── golem
│ │ │ │ │ ├── EntityIronGolem.java
│ │ │ │ │ ├── EntityShulker.java
│ │ │ │ │ ├── EntitySnowman.java
│ │ │ │ │ └── NPCEntityGolem.java
│ │ │ │ └── monster
│ │ │ │ │ ├── EntityCaveSpider.java
│ │ │ │ │ ├── EntityCreeper.java
│ │ │ │ │ ├── EntityEnderman.java
│ │ │ │ │ ├── EntityEndermite.java
│ │ │ │ │ ├── EntityGiant.java
│ │ │ │ │ ├── EntityGuardian.java
│ │ │ │ │ ├── EntityHusk.java
│ │ │ │ │ ├── EntitySkeleton.java
│ │ │ │ │ ├── EntitySpider.java
│ │ │ │ │ ├── EntityWitch.java
│ │ │ │ │ ├── EntityWither.java
│ │ │ │ │ └── NPCEntityMonster.java
│ │ │ │ ├── flying
│ │ │ │ ├── EntityGhast.java
│ │ │ │ └── NPCEntityFlying.java
│ │ │ │ └── water
│ │ │ │ ├── EntitySquid.java
│ │ │ │ └── NPCEntityWaterAnimal.java
│ │ │ ├── equipment
│ │ │ └── EquipmentSlot.java
│ │ │ ├── event
│ │ │ ├── NPCCollisionEvent.java
│ │ │ ├── NPCDamageEvent.java
│ │ │ ├── NPCDeathEvent.java
│ │ │ ├── NPCEvent.java
│ │ │ ├── NPCInteractEvent.java
│ │ │ ├── NPCSpawnEvent.java
│ │ │ ├── NPCVelocityEvent.java
│ │ │ ├── nbt
│ │ │ │ ├── NBTReadEvent.java
│ │ │ │ ├── NBTWriteEvent.java
│ │ │ │ └── NPCNBTEvent.java
│ │ │ └── path
│ │ │ │ └── NPCPathFinishEvent.java
│ │ │ ├── npc
│ │ │ ├── NPCAbstract.java
│ │ │ ├── NPCExperienceOrb.java
│ │ │ ├── NPCItem.java
│ │ │ └── living
│ │ │ │ ├── NPCArmorStand.java
│ │ │ │ ├── NPCLivingAbstract.java
│ │ │ │ ├── human
│ │ │ │ ├── NPCHumanAbstract.java
│ │ │ │ └── NPCPlayer.java
│ │ │ │ └── insentient
│ │ │ │ ├── NPCEnderDragon.java
│ │ │ │ ├── NPCInsentientAbstract.java
│ │ │ │ ├── NPCPigZombie.java
│ │ │ │ ├── NPCSlime.java
│ │ │ │ ├── NPCZombie.java
│ │ │ │ ├── creature
│ │ │ │ ├── NPCCreatureAbstract.java
│ │ │ │ ├── ageable
│ │ │ │ │ ├── NPCAgeableAbstract.java
│ │ │ │ │ ├── NPCVillager.java
│ │ │ │ │ └── animal
│ │ │ │ │ │ ├── NPCAnimalAbstract.java
│ │ │ │ │ │ ├── NPCChicken.java
│ │ │ │ │ │ ├── NPCCow.java
│ │ │ │ │ │ ├── NPCHorse.java
│ │ │ │ │ │ ├── NPCLlama.java
│ │ │ │ │ │ ├── NPCMushroomCow.java
│ │ │ │ │ │ ├── NPCPig.java
│ │ │ │ │ │ ├── NPCPolarBear.java
│ │ │ │ │ │ ├── NPCRabbit.java
│ │ │ │ │ │ ├── NPCSheep.java
│ │ │ │ │ │ └── tameable
│ │ │ │ │ │ ├── NPCOcelot.java
│ │ │ │ │ │ ├── NPCTameableAbstract.java
│ │ │ │ │ │ └── NPCWolf.java
│ │ │ │ ├── golem
│ │ │ │ │ ├── NPCGolemAbstract.java
│ │ │ │ │ ├── NPCIronGolem.java
│ │ │ │ │ ├── NPCShulker.java
│ │ │ │ │ └── NPCSnowman.java
│ │ │ │ └── monster
│ │ │ │ │ ├── NPCCaveSpider.java
│ │ │ │ │ ├── NPCCreeper.java
│ │ │ │ │ ├── NPCEnderman.java
│ │ │ │ │ ├── NPCEndermite.java
│ │ │ │ │ ├── NPCGiant.java
│ │ │ │ │ ├── NPCGuardian.java
│ │ │ │ │ ├── NPCHusk.java
│ │ │ │ │ ├── NPCMonsterAbstract.java
│ │ │ │ │ ├── NPCSkeleton.java
│ │ │ │ │ ├── NPCSpider.java
│ │ │ │ │ ├── NPCWitch.java
│ │ │ │ │ └── NPCWither.java
│ │ │ │ ├── flying
│ │ │ │ ├── NPCFlyingAbstract.java
│ │ │ │ └── NPCGhast.java
│ │ │ │ └── water
│ │ │ │ ├── NPCSquid.java
│ │ │ │ └── NPCWaterAnimalAbstract.java
│ │ │ ├── path
│ │ │ ├── AStarPathfinder.java
│ │ │ ├── NMSPathEntity.java
│ │ │ ├── NMSPathPoint.java
│ │ │ ├── PathPoint.java
│ │ │ └── PathfinderAbstract.java
│ │ │ ├── registry
│ │ │ └── NPCRegistry.java
│ │ │ ├── skin
│ │ │ ├── ISkinnableEntity.java
│ │ │ └── SkinLayer.java
│ │ │ └── watcher
│ │ │ ├── AnnotatedMethodWatcher.java
│ │ │ ├── MethodWatcher.java
│ │ │ └── Watch.java
│ └── resources
│ │ └── npclib.properties
│ └── test
│ └── java
│ └── org
│ └── inventivetalent
│ └── npclib
│ └── test
│ ├── SkinLayerTest.java
│ └── TypeTest.java
├── ISSUE_TEMPLATE.md
├── LICENSE
├── Plugin
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── inventivetalent
│ │ └── npclib
│ │ ├── NPCLibPlugin.java
│ │ ├── command
│ │ └── SpawnCommands.java
│ │ └── metrics
│ │ └── Metrics.java
│ └── resources
│ ├── config.yml
│ └── plugin.yml
├── README.md
├── pom.xml
├── renovate.json
└── settings.xml
/.script/upload-javadoc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo -e "Uploading Javadoc...\n"
3 |
4 | cd $HOME
5 | git config --global user.email "git-bot@inventivetalent.org"
6 | git config --global user.name "InventiveBot"
7 | git clone --quiet --branch=gh-pages https://${GITHUB_TOKEN}@github.com/InventivetalentDev/CompactNPCLib gh-pages > /dev/null
8 |
9 | cd gh-pages
10 | git rm -rf .
11 | cp -Rf $TRAVIS_BUILD_DIR/target/site/apidocs .
12 | git add -f .
13 | git commit -m "Javadoc for #$TRAVIS_BUILD_NUMBER"
14 | git push -fq origin gh-pages > /dev/null
15 |
16 | echo -e "Uploaded Javadoc\n"
17 |
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 |
5 | script: "mvn javadoc:aggregate deploy --settings settings.xml"
6 | before_script:
7 | - "chmod +x .script/upload-javadoc.sh"
8 | after_success: ".script/upload-javadoc.sh"
9 | env:
10 | global:
11 | - secure: "qxDGdJ+QcUTNU3ACL0wLT06CmQhuN/gyi1op/sBWLP1MKR1WBbgsdCeoLNu5JWt008v3rU+cBrk8ZL0zGcnc12BGWqiHmbWX6Y0nHeI7crBxtXV2Nbjb5XXP3PvO5m+2s29Lb4CCUVmgBxPiaKVNbIm6Ax6UMYTvQW+MIh556XCtemhDGqswqgQDptSzk+WPUd86cFhGLTMd1vP8qs0h/Kos34bpF8D+Zi37zbxF4piuS4Z39xKJtkwD96HFbAfY9Cz59WCycj3x5v7Gcyj4k3c5ji6MRq6BEzX1gDJVuwpT+TgJMByAhomNvwmyZdEA48YC5+5CbQ76w1RbzPok79FcsRlvMDccxETMpnuF51BF4vtyMQSSadnJjAh2B0vAbZroroXbI26ndroB5xhloNl3ogHvkGeIpufJTwiWvEUsTP5JkvM+b15+lHbiudh/uLblc0rWX+ld3npwOeZ0sV5gznt+mwKDW+Gz+FIiurJAURIIszHxh3YC2O20ylSAjcKjvF359kQpv0YyOIpOpjXe9XgZFeCzadzXh+RKj1tuQbDbk8/2w+n6/JipwPtdJOfxQKbXg2CQQQaIIgBMV7KvlzxfLqjio4L8G87XAbQKxbsLVFwr1wQN8DQ7LCli13TBjCFkTwKCyatol+cDYsgO0zYjIQo6/n8zkbx8Pn4="
12 | - secure: "hcMNxLwta0O2r/F0+XheR5s/5C6sKHLsptJkw2AG2SUwkSDfXGt/Ob38KyeUegkVQ/kQkOTVZkF4CvDvZLipiPC1BfM+6HuWsIHAkJlgnNBZ/ntj0vCussmkqNJ6hUelK0/XBauGcO5YmqB4Re/TlSlFyHQeLeAG4h38hgQCELsZ3xTl6887+nEy5nLn5xNlzb661BMd6IaRLsm5BMV+8me9ySXMU/+SU9sMZWa7rREOHw6ruFJrW2r5o9FFEJRsuGwmU0MOdYhxM+uD//A+luI0ZO+gneswe/7IAPgwfgCB4qDKBmL4jxokCkcUWfaL3AnfnusP8DXES1b/uQfGtxJNO/uijRHpSD6VnWoz6f3PoTqsez34hzwfawlqZvGxnIQA/wNs76kVfyrjvVib4khkOb/M8ubDVX3lAoX08qojWhYL7lNDY86CqIQ0iWVYKg2j5xVDsiGZ380HYYHjAaEbqDpHqfkwbUtlpn46m2XpoLYGdJhQ/6g4s7hIuHD8n39fvhu0LDd58cRglLqOM5kbWU0Q07GjnL3Aph4XRyMwiFOW+B4UIcl9RfsU3XNy3nispwolwY9wVguUy7Frv3fOHvXf249eD65ayribmFlKLThiuBUzV+hPZ7e4Gz7XyAfpjyJQjiRQ1s2b/OksU0UyQz+Jl77TzUI3Mq4525I="
13 | - secure: "gVPrGhZia3dh30sP0krrRRfa9AJmLIqMvoTWskeyudXe9gSk6ELSSlQwpkhqx4IB+SoFGClm7687t5CbVvN+NLiDymD9uUiY4LmaSbwCHwYgoBL0qJAxeZ8ZjhRoVk1AnVPervjdEHgeXCSePMluGBlYtNfi40vOaa5tv0TT8Fm6B9QwOqU+nZVVaEl7uZjMNd0ZeGbQz/qiErSTBCHC49vevu1u1YqJBIxblHJYSeTp3uvI/SySVcFSY9lFMsWBq0Q3CcKgn7TeAsYsjOjlqEPT7WrA2i7LT7hUWZIA7yGXkknF9TKCjLrXLLgQSVzwImTPXULd+pATMp336DqHVcTzXlfKSJP+YKHuJYYNf17EHHbWW3BviyPcP87weAAJE/LzNQCB96RI9tpcMYcKMWgMollPX15f5wfE7euuLq5jcF2nKvqWtuQOH2XD14bD+9+SN7b2A6ohaud92XXYV5HLFnB0SZZPDURyiLIfzPl14F94nhAkJnCzdQ7JguDXH6eJPhRaIFq1szpBq3rKtmHeHD/37xbFxI3jF/VG1R/PYkyH9BVwaTgiu5z3G0PxoU3tsrYJt7Z92qkkIM40AdhYRReF4aDxcq4Ayd3ewpVNUGpDmCHJumiyH3QqXBhHuU6diWKha8vmsiCCT2deGMqYZSR1Azu4k39W40rP/Xo="
14 | deploy:
15 | provider: releases
16 | api_key:
17 | secure: "onM7hHSoZEr7BrggRPAQz643zghYXI9mXt6rXJeyaqq3EXKn911pOGNsaALcB1iDdrkoumVb9mkX2R0Pn7S5b7JQ00Rb/VvbRjgo9vXUAO3C+KHT8hK1KWH7VPpldMpbJDhGsdbu4j27iOQ9b2PqFnYF9vuqCoIy1q9WQ0BIuYrdA+/ZQ+kShKfqwwrD96D0DZ/68g18vGc6IndKL/2T35MuRMVQVmF137T/BuXKHDVXPKWgeTRY9VMbgh/sI0WhDm2XbyksFeWh6NtUPYxFv10PSJelCJ3c1iqR9wDz0tAuORWGpPMPPIhPCJX07JXotEmz88yFmJXSR5vBddkzaqk5oZpTUlxb4XgtY0ZwJtfzW1x34IKF4db20Tzg3+dRvKlWtfPy5UtbuypiHseltlheEZIciVDW2PdOoKHY3nqP7eeOZCj9DeNpTaa2GWkfc6c8L+IV2K+joJbDp2IEohBKoBKGNDEI+7WQwJWNgJd7qS12Unja1wvDW/Kwryvlwdj5Q9c5qOBgTARQ6Ki5BnZzqYObAkbWaUrEc4xqGIzA7sw51ibFm+oFQabZNAiQUquj0ueeenwgzdRONumw2QAqf8ObQY0xEquaYNS3Bp1IKM+7gvCNqhLuoIfnqRFCJRr+Am2b/YAOTnda+AKThMyNwnjF2XqAhqdGTR8irlE="
18 | file_glob: true
19 | file:
20 | - "API/target/api-*.jar"
21 | - "Plugin/target/NPCLib_v*.jar"
22 | skip_cleanup: true
23 | on:
24 | tags: true
25 |
--------------------------------------------------------------------------------
/API/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
29 |
30 |
33 |
34 | parent
35 | org.inventivetalent.npc-lib
36 | parent
37 |
38 | 4.0.0
39 |
40 | api
41 | ${npclib.version}
42 |
43 |
44 |
45 | inventive-repo
46 | https://repo.inventivetalent.org/content/groups/public/
47 |
48 |
49 | spigot-repo
50 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
51 |
52 |
53 |
54 |
55 |
56 | org.spigotmc
57 | spigot-api
58 | 1.12-R0.1-SNAPSHOT
59 | provided
60 |
61 |
62 | org.inventivetalent
63 | reflectionhelper
64 | ${reflection.version}
65 |
66 |
67 | org.inventivetalent
68 | pluginannotations
69 | ${annotations.version}
70 |
71 |
72 | org.inventivetalent
73 | mc-wrappers
74 | ${wrappers.version}
75 |
76 |
77 | org.inventivetalent
78 | vectors
79 | ${vectors.version}
80 |
81 |
82 | org.inventivetalent
83 | boundingboxapi
84 | ${boundingbox.version}
85 |
86 |
87 | org.inventivetalent
88 | apimanager
89 | ${apimanager.version}
90 |
91 |
92 | org.inventivetalent
93 | nbt-lib
94 | ${nbt.version}
95 |
96 |
97 | org.inventivetalent.nicknamer
98 | api
99 | ${nicknamer.version}
100 |
101 |
102 |
103 | org.projectlombok
104 | lombok
105 | 1.16.8
106 |
107 |
108 | com.google.code.gson
109 | gson
110 | 2.6.2
111 |
112 |
113 | com.google.guava
114 | guava
115 | 19.0
116 |
117 |
118 |
119 | org.javassist
120 | javassist
121 | 3.20.0-GA
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/ArrayMaker.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | public class ArrayMaker {
4 |
5 | public static Object[] fromParameters() {
6 | return new Object[0];
7 | }
8 |
9 | public static Object[] fromParameters(Object... args) {
10 | return args;
11 | }
12 |
13 | public static Object[] fromParameters(Object o) {
14 | return new Object[] { o };
15 | }
16 |
17 | public static Object[] fromParameters(Object o1, Object o2) {
18 | return new Object[] {
19 | o1,
20 | o2 };
21 | }
22 |
23 | public static Object[] fromParameters(Object o1, Object o2, Object o3) {
24 | return new Object[] {
25 | o1,
26 | o2,
27 | o3 };
28 | }
29 |
30 | public static Object[] fromParameters(Object o1, Object o2, Object o3, Object o4) {
31 | return new Object[] {
32 | o1,
33 | o2,
34 | o3,
35 | o4 };
36 | }
37 |
38 | public static Object[] fromParameters(Object o1, Object o2, Object o3, Object o4, Object o5) {
39 | return new Object[] {
40 | o1,
41 | o2,
42 | o3,
43 | o4,
44 | o5 };
45 | }
46 |
47 | public static Object[] fromParameters(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6) {
48 | return new Object[] {
49 | o1,
50 | o2,
51 | o3,
52 | o4,
53 | o5,
54 | o6 };
55 | }
56 |
57 | public static Object[] fromParameters(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7) {
58 | return new Object[] {
59 | o1,
60 | o2,
61 | o3,
62 | o4,
63 | o5,
64 | o6,
65 | o7 };
66 | }
67 |
68 | public static Object[] fromParameters(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8) {
69 | return new Object[] {
70 | o1,
71 | o2,
72 | o3,
73 | o4,
74 | o5,
75 | o6,
76 | o7,
77 | o8 };
78 | }
79 |
80 | public static Object[] fromParameters(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8, Object o9) {
81 | return new Object[] {
82 | o1,
83 | o2,
84 | o3,
85 | o4,
86 | o5,
87 | o6,
88 | o7,
89 | o8,
90 | o9 };
91 | }
92 |
93 | public static Object[] fromParameters(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8, Object o9, Object o10) {
94 | return new Object[] {
95 | o1,
96 | o2,
97 | o3,
98 | o4,
99 | o5,
100 | o6,
101 | o7,
102 | o8,
103 | o9,
104 | o10 };
105 | }
106 |
107 | // Why am I even doing this...
108 | }
109 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/ClassBuilder.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | import javassist.ClassPool;
4 | import org.bukkit.Bukkit;
5 | import org.inventivetalent.reflection.minecraft.Minecraft;
6 | import org.inventivetalent.reflection.resolver.FieldResolver;
7 | import org.inventivetalent.reflection.resolver.MethodResolver;
8 | import org.inventivetalent.reflection.resolver.ResolverQuery;
9 | import org.inventivetalent.reflection.util.AccessUtil;
10 |
11 | import java.lang.reflect.Field;
12 | import java.net.SocketAddress;
13 | import java.util.List;
14 |
15 | public class ClassBuilder {
16 |
17 | protected static Class> nmsPacketPlayOutPlayerInfo;
18 | protected static Class> nmsPlayerInfoData;
19 | protected static Class> nmsEnumPlayerInfoAction;
20 | protected static Class> nmsEnumGamemode;
21 | static Class> generatedChannel;
22 | static Class> generatedPlayerConnection;
23 | static Class> NetworkManager = Reflection.nmsClassResolver.resolveSilent("NetworkManager");
24 |
25 | public static Object buildPacketPlayOutBed(int id, int x, int y, int z) {
26 | try {
27 | Class> packetClass = Reflection.nmsClassResolver.resolve("PacketPlayOutBed");
28 | Object bedPacket = packetClass.newInstance();
29 | AccessUtil.setAccessible(packetClass.getDeclaredField("a")).set(bedPacket, id);
30 | if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) {
31 | AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(bedPacket, x);
32 | AccessUtil.setAccessible(packetClass.getDeclaredField("c")).set(bedPacket, y);
33 | AccessUtil.setAccessible(packetClass.getDeclaredField("d")).set(bedPacket, z);
34 | } else {
35 | AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(bedPacket, Reflection.nmsClassResolver.resolve("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(x, y, z));
36 | }
37 | return bedPacket;
38 | } catch (Exception e) {
39 | throw new RuntimeException(e);
40 | }
41 | }
42 |
43 | public static Object buildPacketPlayOutAnimation(int entID, int animID) {
44 | try {
45 | Class> packetClass = Reflection.nmsClassResolver.resolve("PacketPlayOutAnimation");
46 | Object animationPacket = packetClass.newInstance();
47 | AccessUtil.setAccessible(packetClass.getDeclaredField("a")).set(animationPacket, entID);
48 | AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(animationPacket, animID);
49 |
50 | return animationPacket;
51 | } catch (Exception e) {
52 | throw new RuntimeException(e);
53 | }
54 | }
55 |
56 | public static Object buildPacketPlayOutEntityStatus(int entityId, byte animationId) {
57 | try {
58 | Class> packetClass = Reflection.nmsClassResolver.resolve("PacketPlayOutEntityStatus");
59 | Object animationPacket = packetClass.newInstance();
60 | AccessUtil.setAccessible(packetClass.getDeclaredField("a")).set(animationPacket, entityId);
61 | AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(animationPacket, animationId);
62 |
63 | return animationPacket;
64 | } catch (Exception e) {
65 | throw new RuntimeException(e);
66 | }
67 | }
68 |
69 | public static Object buildPacketPlayOutEntityTeleport(int id, double x, double y, double z, float yaw, float pitch, boolean onGround, boolean heightCorrection) {
70 | try {
71 | Class> packetClass = Reflection.nmsClassResolver.resolve("PacketPlayOutEntityTeleport");
72 | Object teleportPacket;
73 | if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) {
74 | teleportPacket = packetClass.getConstructor(int.class, int.class, int.class, int.class, byte.class, byte.class, boolean.class, boolean.class)
75 | .newInstance(id, floor(x * 32.0D), floor(y * 32.0D), floor(z * 32.0D), (byte) (int) (yaw * 256F / 360F), (byte) (int) (pitch * 256F / 360F), onGround, heightCorrection);
76 | } else if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) {
77 | teleportPacket = packetClass.getConstructor(int.class, int.class, int.class, int.class, byte.class, byte.class, boolean.class)
78 | .newInstance(id, floor(x * 32.0D), floor(y * 32.0D), floor(z * 32.0D), (byte) (int) (yaw * 256F / 360F), (byte) (int) (pitch * 256F / 360F), onGround);
79 | } else {
80 | teleportPacket = packetClass.newInstance();
81 | AccessUtil.setAccessible(packetClass.getDeclaredField("a")).set(teleportPacket, id);
82 | AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(teleportPacket, x);
83 | AccessUtil.setAccessible(packetClass.getDeclaredField("c")).set(teleportPacket, y);
84 | AccessUtil.setAccessible(packetClass.getDeclaredField("d")).set(teleportPacket, z);
85 | AccessUtil.setAccessible(packetClass.getDeclaredField("e")).set(teleportPacket, (byte) (int) (yaw * 256F / 360F));
86 | AccessUtil.setAccessible(packetClass.getDeclaredField("f")).set(teleportPacket, (byte) (int) (pitch * 256F / 360F));
87 | AccessUtil.setAccessible(packetClass.getDeclaredField("g")).set(teleportPacket, onGround);
88 | }
89 |
90 | return teleportPacket;
91 | } catch (Exception e) {
92 | throw new RuntimeException(e);
93 | }
94 | }
95 |
96 | public static int floor(double d1) {
97 | int i = (int) d1;
98 | return d1 >= i ? i : i - 1;
99 | }
100 |
101 | static Class> PacketListener = Reflection.nmsClassResolver.resolveSilent("PacketListener");
102 | //
103 | // public static Object buildWatchableObject(int type, int index, Object value) throws Exception {
104 | // return NMSClass.nmsWatchableObject.getConstructor(int.class, int.class, Object.class).newInstance(type, index, value);
105 | // }
106 | //
107 | // public static Object setDataWatcherValue(Object dataWatcher, int index, Object value) throws Exception {
108 | // int type = getDataWatcherValueType(value);
109 | //
110 | // Object map = AccessUtil.setAccessible(NMSClass.nmsDataWatcher.getDeclaredField("dataValues")).get(dataWatcher);
111 | // NMUClass.gnu_trove_map_hash_TIntObjectHashMap.getDeclaredMethod("put", int.class, Object.class).invoke(map, index, buildWatchableObject(type, index, value));
112 | //
113 | // return dataWatcher;
114 | // }
115 | //
116 | // public static int getDataWatcherValueType(Object value) {
117 | // int type = 0;
118 | // if (value instanceof Number) {
119 | // if (value instanceof Byte) {
120 | // type = 0;
121 | // } else if (value instanceof Short) {
122 | // type = 1;
123 | // } else if (value instanceof Integer) {
124 | // type = 2;
125 | // } else if (value instanceof Float) {
126 | // type = 3;
127 | // }
128 | // } else if (value instanceof String) {
129 | // type = 4;
130 | // }
131 | // // Should not be needed
132 | // // else if (value != null && value.getClass().equals(NMSClass.ItemStack)) {
133 | // // type = 5;
134 | // // } else if (value != null && (value.getClass().equals(NMSClass.ChunkCoordinates) || value.getClass().equals(NMSClass.BlockPosition))) {
135 | // // type = 6;
136 | // // } else if (value != null && value.getClass().equals(NMSClass.Vector3f)) {
137 | // // type = 7;
138 | // // }
139 | //
140 | // return type;
141 | // }
142 |
143 | // public static Object getDataWatcher(org.bukkit.entity.Entity ent) {
144 | // try {
145 | // return NMSClass.nmsEntity.getDeclaredMethod("getDataWatcher").invoke(Reflection.getHandle(ent));
146 | // } catch (Exception e) {
147 | // e.printStackTrace();
148 | // }
149 | // return null;
150 | // }
151 | static FieldResolver NetworkManagerFieldResolver = new FieldResolver(NetworkManager);
152 | static MethodResolver NetworkManagerMethodResolver = new MethodResolver(NetworkManager);
153 | private static boolean initialized = false;
154 |
155 | static {
156 | try {
157 | ClassPool classPool = ClassPool.getDefault();
158 | generatedChannel = ClassGenerator.generateChannel(classPool);
159 | generatedPlayerConnection = ClassGenerator.generatePlayerConnection(classPool);
160 | } catch (Exception e) {
161 | throw new RuntimeException(e);
162 | }
163 | }
164 |
165 | static {
166 | if (!initialized) {
167 | try {
168 | nmsPacketPlayOutPlayerInfo = Reflection.nmsClassResolver.resolve("PacketPlayOutPlayerInfo");
169 | if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_8_R1)) {
170 | // if (NPCLib.getServerVersion() <= 181) {
171 | // nmsPlayerInfoData = Reflection.getNMSClassWithException("PlayerInfoData");
172 | // } else {
173 | // nmsPlayerInfoData = Reflection.getNMSClassWithException("PacketPlayOutPlayerInfo$PlayerInfoData");
174 | // }
175 | nmsPlayerInfoData = Reflection.nmsClassResolver.resolve("PlayerInfoData", "PacketPlayOutPlayerInfo$PlayerInfoData");
176 | // if (NPCLib.getServerVersion() <= 181) {
177 | // nmsEnumPlayerInfoAction = Reflection.getNMSClassWithException("EnumPlayerInfoAction");
178 | // } else {
179 | // nmsEnumPlayerInfoAction = Reflection.getNMSClassWithException("PacketPlayOutPlayerInfo$EnumPlayerInfoAction");
180 | // }
181 | nmsEnumPlayerInfoAction = Reflection.nmsClassResolver.resolve("EnumPlayerInfoAction", "PacketPlayOutPlayerInfo$EnumPlayerInfoAction");
182 | }
183 | // if (NPCLib.getServerVersion() <= 181) {
184 | // nmsEnumGamemode = Reflection.getNMSClassWithException("EnumGamemode");
185 | // } else {
186 | // nmsEnumGamemode = Reflection.getNMSClassWithException("WorldSettings$EnumGamemode");
187 | // }
188 | nmsEnumGamemode = Reflection.nmsClassResolver.resolve("EnumGamemode", "WorldSettings$EnumGamemode");
189 | initialized = true;
190 | } catch (Exception e) {
191 | e.printStackTrace();
192 | }
193 | }
194 | }
195 |
196 | public static Object buildPlayerConnection(Object networkManager, Object entity) throws Exception {
197 | final Object playerConnection = generatedPlayerConnection.getDeclaredConstructor(Reflection.nmsClassResolver.resolve("MinecraftServer"), networkManager.getClass(), Reflection.nmsClassResolver.resolve("EntityPlayer")).newInstance(new MethodResolver(Bukkit.getServer().getClass()).resolve("getServer").invoke(Bukkit.getServer()), networkManager, entity);
198 | NetworkManagerMethodResolver.resolve(new ResolverQuery("setPacketListener", PacketListener), new ResolverQuery("a", PacketListener)).invoke(networkManager, playerConnection);
199 | return playerConnection;
200 | }
201 |
202 | public static Object buildNetworkManager(boolean clientBound) throws Exception {
203 | Object networkManager = Reflection.nmsClassResolver.resolve("NetworkManager").getConstructor(Reflection.nmsClassResolver.resolve("EnumProtocolDirection")).newInstance(Reflection.nmsClassResolver.resolve("EnumProtocolDirection").getEnumConstants()[clientBound ? 0 : 1]);
204 |
205 | Field channelField = NetworkManagerFieldResolver.resolveByFirstType(Reflection.classResolver.resolve("io.netty.channel.Channel"));
206 | Field addressField = NetworkManagerFieldResolver.resolveByFirstType(SocketAddress.class);
207 |
208 | Object parentChannel = generatedChannel.newInstance();
209 |
210 | try {
211 | Field protocolVersionField = Reflection.nmsClassResolver.resolve("NetworkManager").getDeclaredField("c");
212 | Object attribute = getNMUtilClass("io.netty.util.AttributeMap").getDeclaredMethod("attr", getNMUtilClass("io.netty.util.AttributeKey")).invoke(parentChannel, protocolVersionField.get(null));
213 | getNMUtilClass("io.netty.util.Attribute").getDeclaredMethod("set", Object.class).invoke(attribute, 5);// TODO version based protocol
214 | } catch (NoSuchFieldException e) {
215 | e.printStackTrace();
216 | }
217 |
218 | channelField.set(networkManager, parentChannel);
219 | addressField.set(networkManager, new SocketAddress() {
220 | private static final long serialVersionUID = 1108301788933825435L;
221 | });
222 |
223 | return networkManager;
224 | }
225 |
226 | @SuppressWarnings({
227 | "rawtypes",
228 | "unchecked" })
229 | public static Object buildPlayerInfoPacket(int action, Object profile, int ping, int gamemodeOrdinal, String name) {
230 | try {
231 | Object packet = nmsPacketPlayOutPlayerInfo.newInstance();
232 |
233 | if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) {
234 | AccessUtil.setAccessible(nmsPacketPlayOutPlayerInfo.getDeclaredField("action")).set(packet, action);
235 | AccessUtil.setAccessible(nmsPacketPlayOutPlayerInfo.getDeclaredField("player")).set(packet, profile);
236 | AccessUtil.setAccessible(nmsPacketPlayOutPlayerInfo.getDeclaredField("gamemode")).set(packet, gamemodeOrdinal);
237 | AccessUtil.setAccessible(nmsPacketPlayOutPlayerInfo.getDeclaredField("ping")).set(packet, ping);
238 | AccessUtil.setAccessible(nmsPacketPlayOutPlayerInfo.getDeclaredField("username")).set(packet, name);
239 | } else {
240 | AccessUtil.setAccessible(nmsPacketPlayOutPlayerInfo.getDeclaredField("a")).set(packet, nmsEnumPlayerInfoAction.getEnumConstants()[action]);
241 | List list = (List) AccessUtil.setAccessible(nmsPacketPlayOutPlayerInfo.getDeclaredField("b")).get(packet);
242 |
243 | Object data;
244 | // if (NPCLib.getServerVersion() <= 181) {
245 | data = nmsPlayerInfoData.getConstructor(nmsPacketPlayOutPlayerInfo, getNMUtilClass("com.mojang.authlib.GameProfile"), int.class, nmsEnumGamemode, Reflection.nmsClassResolver.resolve("IChatBaseComponent")).newInstance(packet, profile, ping, nmsEnumGamemode.getEnumConstants()[gamemodeOrdinal], buildChatComponent(name));
246 | // } else {
247 | // data = nmsPlayerInfoData.getConstructor(getNMUtilClass("com.mojang.authlib.GameProfile"), int.class, nmsEnumGamemode,
248 | // Reflection.getNMSClass("IChatBaseComponent")).newInstance(profile, ping, nmsEnumGamemode.getEnumConstants()[gamemodeOrdinal], buildChatComponent(name));
249 | // }
250 | list.add(data);
251 | }
252 | return packet;
253 | } catch (Exception e) {
254 | e.printStackTrace();
255 | }
256 | return null;
257 | }
258 |
259 | public static Object buildChatComponent(String string) {
260 | Object comp = null;
261 | try {
262 | Object[] components = (Object[]) Reflection.obcClassResolver.resolve("util.CraftChatMessage").getMethod("fromString", String.class).invoke(null, string);
263 | if (components.length > 0) {
264 | comp = components[0];
265 | }
266 | } catch (Exception e) {
267 | e.printStackTrace();
268 | }
269 | return comp;
270 | }
271 |
272 | public static Class> getNMUtilClass(String name) throws ClassNotFoundException {
273 | if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) { return Class.forName("net.minecraft.util." + name); } else { return Class.forName(name); }
274 | }
275 | }
276 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/INPCChannel.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | public interface INPCChannel {
4 |
5 | void setOpen(boolean open);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/INPCPlayerConnection.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | public interface INPCPlayerConnection {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/NPCLib.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | import com.google.common.base.Joiner;
4 | import com.mojang.authlib.GameProfile;
5 | import lombok.NonNull;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.entity.Entity;
8 | import org.bukkit.entity.Player;
9 | import org.bukkit.plugin.Plugin;
10 | import org.inventivetalent.apihelper.API;
11 | import org.inventivetalent.npclib.entity.NPCEntity;
12 | import org.inventivetalent.npclib.event.NPCInteractEvent;
13 | import org.inventivetalent.npclib.npc.NPCAbstract;
14 | import org.inventivetalent.npclib.npc.living.human.NPCPlayer;
15 | import org.inventivetalent.npclib.registry.NPCRegistry;
16 | import org.inventivetalent.packetlistener.handler.PacketHandler;
17 | import org.inventivetalent.packetlistener.handler.PacketOptions;
18 | import org.inventivetalent.packetlistener.handler.ReceivedPacket;
19 | import org.inventivetalent.packetlistener.handler.SentPacket;
20 | import org.inventivetalent.reflection.minecraft.Minecraft;
21 |
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.util.Properties;
25 | import java.util.UUID;
26 | import java.util.logging.Level;
27 | import java.util.logging.Logger;
28 |
29 | public class NPCLib implements API {
30 |
31 | public static Logger logger = Logger.getLogger("NPCLib");
32 | public static boolean debug;
33 |
34 | public static NPCRegistry createRegistry(@NonNull Plugin plugin) {
35 | // return Reflection.newInstance("org.inventivetalent.npc.registry", "NPCRegistry", NPCRegistry.class, plugin);
36 | return new NPCRegistry(plugin);
37 | }
38 |
39 | public static boolean isNPC(Entity entity) {
40 | if (entity == null) { return false; }
41 | try {
42 | return Minecraft.getHandle(entity) instanceof NPCEntity;
43 | } catch (Exception e) {
44 | throw new RuntimeException(e);
45 | }
46 | }
47 |
48 | public static NPCAbstract, ?> getNPC(Entity entity) {
49 | if (entity == null) { return null; }
50 | try {
51 | Object handle = Minecraft.getHandle(entity);
52 | if (handle instanceof NPCEntity) {
53 | return ((NPCEntity) handle).getNPC();
54 | }
55 | } catch (Exception e) {
56 | throw new RuntimeException(e);
57 | }
58 | return null;
59 | }
60 |
61 | public static void debug(Object... message) {
62 | if (debug) { logger.info("[DEBUG] " + Joiner.on(" ").join(message)); }
63 | }
64 |
65 | public static final String getVersion() {
66 | try (InputStream in = NPCLib.class.getResourceAsStream("/npclib.properties")) {
67 | Properties properties = new Properties();
68 | properties.load(in);
69 | return properties.getProperty("npclib.version");
70 | } catch (IOException e) {
71 | logger.log(Level.WARNING, "Failed to get API version from npclib.properties", e);
72 | return "0.0.0";
73 | }
74 | }
75 |
76 | @Override
77 | public void load() {
78 | long start = System.currentTimeMillis();
79 | Class>[] classes = new Class[NPCType.values().length];
80 | for (int i = 0; i < classes.length; ) {
81 | if (NPCType.values()[i].isAvailable()) {
82 | classes[i] = NPCType.values()[i].getNpcClass();
83 | }
84 | i++;
85 | }
86 | NPCRegistry.injectClasses(classes);
87 | long end = System.currentTimeMillis();
88 | long diff = end - start;
89 | logger.info("Generated & Injected available entity classes in " + (diff / 1000D) + "s");
90 | }
91 |
92 | @Override
93 | public void init(final Plugin plugin) {
94 | PacketHandler.addHandler(new PacketHandler(plugin) {
95 | @PacketOptions(forcePlayer = true)
96 | @Override
97 | public void onSend(final SentPacket sentPacket) {
98 | if (sentPacket.hasPlayer()) {
99 | if ("PacketPlayOutNamedEntitySpawn".equals(sentPacket.getPacketName())) {
100 | final Player player = sentPacket.getPlayer();
101 | final UUID uuid = Minecraft.VERSION.newerThan(Minecraft.Version.v1_8_R1) ?
102 | ((UUID) sentPacket.getPacketValue("b")) :
103 | (((GameProfile) sentPacket.getPacketValue("b")).getId());
104 | Player npcPlayer = null;
105 | //TODO: check if this doesn't cause any ConcurrentModExceptions / make this synchronous somehow
106 | for (Player worldPlayer : player.getWorld().getPlayers()) {// We can't use Bukkit#getOnlinePlayers, since the server doesn't know about the player NPCs
107 | if (worldPlayer.getUniqueId().equals(uuid)) {
108 | npcPlayer = worldPlayer;
109 | break;
110 | }
111 | }
112 | if (npcPlayer != null) {
113 | NPCAbstract, ?> npcAbstract = NPCLib.getNPC(npcPlayer);
114 | if (npcAbstract != null && npcAbstract instanceof NPCPlayer) {
115 | ((NPCPlayer) npcAbstract).updateToPlayer(player);
116 | }
117 | }
118 | }
119 | }
120 | }
121 |
122 | @PacketOptions(forcePlayer = true)
123 | @Override
124 | public void onReceive(ReceivedPacket receivedPacket) {
125 | if (receivedPacket.hasPlayer()) {
126 | if ("PacketPlayInUseEntity".equals(receivedPacket.getPacketName())) {
127 | int a = (int) receivedPacket.getPacketValue(0);
128 | Entity entity = Reflection.getEntityById(receivedPacket.getPlayer().getWorld(), a);
129 | if (entity == null || !NPCLib.isNPC(entity)) {
130 | return;
131 | }
132 | Enum> action = (Enum>) receivedPacket.getPacketValue(1);
133 |
134 | NPCInteractEvent event = new NPCInteractEvent(NPCLib.getNPC(entity), a, action == null ? -1 : action.ordinal(), receivedPacket.getPlayer());
135 | Bukkit.getPluginManager().callEvent(event);
136 | if (event.isCancelled()) {
137 | receivedPacket.setCancelled(true);
138 | }
139 | }
140 | }
141 | }
142 | });
143 |
144 | String version = getVersion();
145 | logger.info("Version is " + version);
146 | }
147 |
148 | @Override
149 | public void disable(Plugin plugin) {
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/NPCType.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | import com.google.common.base.Strings;
4 | import com.google.common.collect.Maps;
5 | import lombok.Getter;
6 | import org.bukkit.entity.EntityType;
7 | import org.inventivetalent.npclib.npc.NPCAbstract;
8 | import org.inventivetalent.npclib.npc.NPCExperienceOrb;
9 | import org.inventivetalent.npclib.npc.NPCItem;
10 | import org.inventivetalent.npclib.npc.living.NPCArmorStand;
11 | import org.inventivetalent.npclib.npc.living.human.NPCPlayer;
12 | import org.inventivetalent.npclib.npc.living.insentient.NPCEnderDragon;
13 | import org.inventivetalent.npclib.npc.living.insentient.NPCPigZombie;
14 | import org.inventivetalent.npclib.npc.living.insentient.NPCSlime;
15 | import org.inventivetalent.npclib.npc.living.insentient.NPCZombie;
16 | import org.inventivetalent.npclib.npc.living.insentient.creature.ageable.NPCVillager;
17 | import org.inventivetalent.npclib.npc.living.insentient.creature.ageable.animal.*;
18 | import org.inventivetalent.npclib.npc.living.insentient.creature.ageable.animal.tameable.NPCOcelot;
19 | import org.inventivetalent.npclib.npc.living.insentient.creature.ageable.animal.tameable.NPCWolf;
20 | import org.inventivetalent.npclib.npc.living.insentient.creature.golem.NPCIronGolem;
21 | import org.inventivetalent.npclib.npc.living.insentient.creature.golem.NPCShulker;
22 | import org.inventivetalent.npclib.npc.living.insentient.creature.golem.NPCSnowman;
23 | import org.inventivetalent.npclib.npc.living.insentient.creature.monster.*;
24 | import org.inventivetalent.npclib.npc.living.insentient.flying.NPCGhast;
25 | import org.inventivetalent.npclib.npc.living.insentient.water.NPCSquid;
26 |
27 | import java.util.Map;
28 |
29 | import static com.google.common.base.Preconditions.checkNotNull;
30 |
31 | public enum NPCType {
32 | DROPPED_ITEM("DROPPED_ITEM", NPCItem.class),
33 | EXPERIENCE_ORB("EXPERIENCE_ORB", NPCExperienceOrb.class),
34 |
35 | HUSK("HUSK", NPCHusk.class),
36 |
37 | ARMOR_STAND("ARMOR_STAND", NPCArmorStand.class),
38 |
39 | CREEPER("CREEPER", NPCCreeper.class),
40 | SKELETON("SKELETON", NPCSkeleton.class),
41 | SPIDER("SPIDER", NPCSpider.class),
42 | GIANT("GIANT", NPCGiant.class),
43 | ZOMBIE("ZOMBIE", NPCZombie.class),
44 | SLIME("SLIME", NPCSlime.class),
45 | GHAST("GHAST", NPCGhast.class),
46 | PIG_ZOMBIE("PIG_ZOMBIE", NPCPigZombie.class),
47 | ENDERMAN("ENDERMAN", NPCEnderman.class),
48 | CAVE_SPIDER("CAVE_SPIDER", NPCCaveSpider.class),
49 | ENDER_DRAGON("ENDER_DRAGON", NPCEnderDragon.class),
50 | WITHER("WITHER", NPCWither.class),
51 | WITCH("WITCH", NPCWitch.class),
52 | ENDERMITE("ENDERMITE", NPCEndermite.class),
53 | GUARDIAN("GUARDIAN", NPCGuardian.class),
54 | SHULKER("SHULKER", NPCShulker.class),
55 |
56 | PIG("PIG", NPCPig.class),
57 | SHEEP("SHEEP", NPCSheep.class),
58 | COW("COW", NPCCow.class),
59 | CHICKEN("CHICKEN", NPCChicken.class),
60 | SQUID("SQUID", NPCSquid.class),
61 | WOLF("WOLF", NPCWolf.class),
62 | MUSHROOM_COW("MUSHROOM_COW", NPCMushroomCow.class),
63 | SNOWMAN("SNOWMAN", NPCSnowman.class),
64 | OCELOT("OCELOT", NPCOcelot.class),
65 | IRON_GOLEM("IRON_GOLEM", NPCIronGolem.class),
66 | HORSE("HORSE", NPCHorse.class),
67 | RABBIT("RABBIT", NPCRabbit.class),
68 | POLAR_BEAR("POLAR_BEAR", NPCPolarBear.class),
69 | LLAMA("LLAMA", NPCLlama.class),
70 |
71 | VILLAGER("VILLAGER", NPCVillager.class),
72 |
73 | PLAYER("PLAYER", NPCPlayer.class);
74 |
75 | private static final Map entityTypeMap = Maps.newHashMap();
76 | private static final Map>, NPCType> classMap = Maps.newHashMap();
77 |
78 | static {
79 | for (NPCType npcType : values()) {
80 | if (npcType.entityType != null) {
81 | entityTypeMap.put(npcType.entityType, npcType);
82 | }
83 | if (npcType.npcClass != null) {
84 | classMap.put(npcType.npcClass, npcType);
85 | }
86 | }
87 | }
88 |
89 | @Getter private EntityType entityType;
90 | @Getter private Class extends NPCAbstract, ?>> npcClass;
91 |
92 | NPCType(EntityType entityType, Class extends NPCAbstract, ?>> npcClass) {
93 | this.entityType = entityType;
94 | this.npcClass = npcClass;
95 | }
96 |
97 | NPCType(String entityTypeName, Class extends NPCAbstract, ?>> npcClass) {
98 | try {
99 | this.entityType = EntityType.valueOf(entityTypeName);
100 | this.npcClass = npcClass;
101 | } catch (NoSuchFieldError | IllegalArgumentException ignored) {
102 | NPCLib.logger.warning("NPCType " + name() + " is not supported on this server version");
103 | }
104 | }
105 |
106 | public static NPCType forEntityType(EntityType entityType) {
107 | return entityTypeMap.get(checkNotNull(entityType));
108 | }
109 |
110 | public static NPCType forNpcClass(Class extends NPCAbstract, ?>> clazz) {
111 | return classMap.get(clazz);
112 | }
113 |
114 | public static NPCType fromString(String string) {
115 | if (Strings.isNullOrEmpty(string)) { return null; }
116 | NPCType type;
117 | if ((type = valueOfOrNull(string.toUpperCase())) != null) {
118 | return type;
119 | }
120 | if ((type = valueOfOrNull(string.toUpperCase().replace(" ", "_"))) != null) {
121 | return type;
122 | }
123 | if ((type = valueOfOrNull(string.toUpperCase().replaceAll("\\s", ""))) != null) {
124 | return type;
125 | }
126 | for (NPCType npcType : values()) {
127 | String combined = npcType.name().replace("_", "");
128 | if (combined.equals(string.toUpperCase())) {
129 | return npcType;
130 | }
131 | }
132 | return null;
133 | }
134 |
135 | private static NPCType valueOfOrNull(String string) {
136 | try {
137 | return valueOf(string);
138 | } catch (IllegalArgumentException e) {
139 | return null;
140 | }
141 | }
142 |
143 | /**
144 | * Check if this NPC type is available for the current server version
145 | *
146 | * @return whether this type is available
147 | */
148 | public boolean isAvailable() {
149 | return this.entityType != null && this.npcClass != null;
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/ObjectContainer.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 |
7 | @Data
8 | @AllArgsConstructor
9 | @EqualsAndHashCode
10 | public class ObjectContainer {
11 |
12 | public T value;
13 |
14 | public static ObjectContainer[] fromObjects(Object[] objects) {
15 | ObjectContainer[] containers = new ObjectContainer[objects.length];
16 | for (int i = 0; i < objects.length; i++)
17 | containers[i] = new ObjectContainer<>(objects[i]);
18 | return containers;
19 | }
20 |
21 | public static Object[] toObjects(ObjectContainer[] containers) {
22 | Object[] objects = new Object[containers.length];
23 | for (int i = 0; i < containers.length; i++)
24 | objects[i] = containers[i].value;
25 | return objects;
26 | }
27 |
28 | @Override
29 | public String toString() {
30 | if (value == null) { return "ObjectContainer[null]"; }
31 | return value.toString();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/ObjectConverter.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | public class ObjectConverter {
4 |
5 | public static Object toObject(Object o) {
6 | return o;
7 | }
8 |
9 | public static Object toObject(byte b) {
10 | return Byte.valueOf(b);
11 | }
12 |
13 | public static Object toObject(short s) {
14 | return Short.valueOf(s);
15 | }
16 |
17 | public static Object toObject(int i) {
18 | return Integer.valueOf(i);
19 | }
20 |
21 | public static Object toObject(long l) {
22 | return Long.valueOf(l);
23 | }
24 |
25 | public static Object toObject(float f) {
26 | return Float.valueOf(f);
27 | }
28 |
29 | public static Object toObject(double d) {
30 | return Double.valueOf(d);
31 | }
32 |
33 | public static Object toObject(boolean b) {
34 | return Boolean.valueOf(b);
35 | }
36 |
37 | public static Object toObject(char c) {
38 | return Character.valueOf(c);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/Reflection.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | import org.bukkit.World;
4 | import org.bukkit.entity.Entity;
5 | import org.bukkit.event.entity.EntityDamageEvent;
6 | import org.inventivetalent.reflection.minecraft.Minecraft;
7 | import org.inventivetalent.reflection.resolver.ClassResolver;
8 | import org.inventivetalent.reflection.resolver.MethodResolver;
9 | import org.inventivetalent.reflection.resolver.ResolverQuery;
10 | import org.inventivetalent.reflection.resolver.minecraft.NMSClassResolver;
11 | import org.inventivetalent.reflection.resolver.minecraft.OBCClassResolver;
12 | import org.inventivetalent.reflection.resolver.wrapper.MethodWrapper;
13 | import org.inventivetalent.reflection.util.AccessUtil;
14 |
15 | import java.lang.reflect.Field;
16 | import java.lang.reflect.Method;
17 |
18 | public class Reflection {
19 |
20 | public static final boolean is1_9 = Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1);
21 | public static final boolean is1_8 = !is1_9 && Minecraft.VERSION.newerThan(Minecraft.Version.v1_8_R1);
22 | public static final boolean is1_7 = !is1_8 && Minecraft.VERSION.newerThan(Minecraft.Version.v1_7_R1);
23 |
24 | public static final ClassResolver classResolver = new ClassResolver();
25 | public static final NMSClassResolver nmsClassResolver = new NMSClassResolver();
26 | public static final OBCClassResolver obcClassResolver = new OBCClassResolver();
27 |
28 | public static boolean doesClassExist(String name) {
29 | try {
30 | return Class.forName(name) != null;
31 | } catch (ClassNotFoundException e) {
32 | }
33 | return false;
34 | }
35 |
36 | public static String getMethodSignature(Method method) {
37 | // StringBuilder stringBuilder = new StringBuilder(method.getName());
38 | // stringBuilder.append("(");
39 | //
40 | // boolean first = true;
41 | // for (Class clazz : method.getParameterTypes()) {
42 | // if (!first) { stringBuilder.append(","); }
43 | // stringBuilder.append(clazz.getSimpleName());
44 | // first = false;
45 | // }
46 | // return stringBuilder.append(")").toString();
47 | return MethodWrapper.getMethodSignature(method, false);
48 | }
49 |
50 | public static String getDamageSourceName(Object damageSource) {
51 | if (damageSource != null) {
52 | try {
53 | return (String) Reflection.nmsClassResolver.resolve("DamageSource").getField("translationIndex").get(damageSource);
54 | } catch (ReflectiveOperationException e) {
55 | throw new RuntimeException(e);
56 | }
57 | }
58 | return null;
59 | }
60 |
61 | public static EntityDamageEvent.DamageCause damageSourceToCause(String damageName) {
62 | if (damageName == null) {
63 | return EntityDamageEvent.DamageCause.VOID;
64 | }
65 | EntityDamageEvent.DamageCause cause = EntityDamageEvent.DamageCause.CUSTOM;
66 | switch (damageName) {
67 | case "inFire":
68 | cause = EntityDamageEvent.DamageCause.FIRE;
69 | break;
70 | case "onFire":
71 | cause = EntityDamageEvent.DamageCause.FIRE_TICK;
72 | break;
73 | case "lava":
74 | cause = EntityDamageEvent.DamageCause.LAVA;
75 | break;
76 | case "inWall":
77 | cause = EntityDamageEvent.DamageCause.SUFFOCATION;
78 | break;
79 | case "drown":
80 | cause = EntityDamageEvent.DamageCause.DROWNING;
81 | break;
82 | case "starve":
83 | cause = EntityDamageEvent.DamageCause.STARVATION;
84 | break;
85 | case "cactus":
86 | cause = EntityDamageEvent.DamageCause.CONTACT;
87 | break;
88 | case "fall":
89 | cause = EntityDamageEvent.DamageCause.FALL;
90 | break;
91 | case "outOfWorld":
92 | cause = EntityDamageEvent.DamageCause.VOID;
93 | break;
94 | case "generic":
95 | cause = EntityDamageEvent.DamageCause.CUSTOM;
96 | break;
97 | case "indirectMagic":
98 | cause = EntityDamageEvent.DamageCause.MAGIC;
99 | break;
100 | case "magic":
101 | cause = EntityDamageEvent.DamageCause.POISON;
102 | break;
103 | case "wither":
104 | cause = EntityDamageEvent.DamageCause.WITHER;
105 | break;
106 | case "anvil":
107 | case "fallingBlock":
108 | cause = EntityDamageEvent.DamageCause.FALLING_BLOCK;
109 | break;
110 | case "thorns":
111 | cause = EntityDamageEvent.DamageCause.THORNS;
112 | break;
113 | case "fireball":
114 | case "arrow":
115 | cause = EntityDamageEvent.DamageCause.PROJECTILE;
116 | break;
117 | case "thrown":// No idea what causes this
118 | case "mob":
119 | case "player":
120 | cause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
121 | break;
122 | case "explosion.player":
123 | case "explosion":
124 | cause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;
125 | break;
126 | case "dragonBreath":
127 | cause = EntityDamageEvent.DamageCause.DRAGON_BREATH;
128 | break;
129 | case "flyIntoWall":
130 | cause = EntityDamageEvent.DamageCause.FLY_INTO_WALL;
131 | break;
132 | case "hotFloor":
133 | cause = EntityDamageEvent.DamageCause.HOT_FLOOR;
134 | break;
135 | default:
136 | break;
137 | }
138 | return cause;
139 | }
140 |
141 | public static Entity getEntityFromDamageSource(Object damageSource) {
142 | if (damageSource == null) { return null; }
143 | try {
144 | Class> classDamageSource = nmsClassResolver.resolve("DamageSource");
145 | Object nmsEntity = classDamageSource.getDeclaredMethod("getEntity").invoke(damageSource);
146 | if (nmsEntity == null) { return null; }
147 | return Minecraft.getBukkitEntity(nmsEntity);
148 | } catch (ReflectiveOperationException e) {
149 | throw new RuntimeException();
150 | }
151 | }
152 |
153 | public static Entity getEntityById(World world, int id) {
154 | try {
155 | Field mapField = AccessUtil.setAccessible(nmsClassResolver.resolve("World").getDeclaredField("entitiesById"));
156 | Object nmsEntity = nmsClassResolver.resolve("IntHashMap").getDeclaredMethod("get", int.class).invoke(mapField.get(Minecraft.getHandle(world)), id);
157 | return nmsEntity == null ? null : Minecraft.getBukkitEntity(nmsEntity);
158 | } catch (ReflectiveOperationException e) {
159 | throw new RuntimeException(e);
160 | }
161 | }
162 |
163 | public static void mergeNBTCompound(Object originalTag, Object toMerge) {
164 | try {
165 | Class> clazz = nmsClassResolver.resolve("NBTTagCompound");
166 | Method method = new MethodResolver(clazz).resolve(new ResolverQuery("merge", clazz)/*(SRG mapping)*/, new ResolverQuery("a", clazz));
167 | method.invoke(originalTag, toMerge);
168 | } catch (ReflectiveOperationException e) {
169 | throw new RuntimeException(e);
170 | }
171 | }
172 |
173 | public static Object getDataWatcher(org.bukkit.entity.Entity ent) {
174 | try {
175 | return nmsClassResolver.resolve("Entity").getDeclaredMethod("getDataWatcher").invoke(Minecraft.getHandle(ent));
176 | } catch (Exception e) {
177 | e.printStackTrace();
178 | }
179 | return null;
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/SuperSwitch.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib;
2 |
3 | import lombok.*;
4 | import org.bukkit.event.Cancellable;
5 |
6 | @Data
7 | @NoArgsConstructor
8 | @AllArgsConstructor
9 | @EqualsAndHashCode
10 | @ToString
11 | public class SuperSwitch implements Cancellable {
12 |
13 | private State state = State.PASS;
14 |
15 | public static SuperSwitch newInstance() {
16 | return new SuperSwitch();
17 | }
18 |
19 | @Override
20 | public boolean isCancelled() {
21 | return this.state == State.CANCEL;
22 | }
23 |
24 | @Override
25 | public void setCancelled(boolean b) {
26 | this.state = State.CANCEL;
27 | }
28 |
29 | public boolean callSuper() {
30 | return this.state == State.PASS || this.state == State.REPLACE;
31 | }
32 |
33 | public boolean isReplace() {
34 | return this.state == State.REPLACE;
35 | }
36 |
37 | public enum State {
38 | /**
39 | * Let the call pass and return the default value by calling the super method
40 | */
41 | PASS,
42 | /**
43 | * Cancel the call entirely and don't call super
44 | */
45 | CANCEL,
46 | /**
47 | * Call super, but replace the returned value of the method
48 | */
49 | REPLACE;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/ai/AIAbstract.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.ai;
2 |
3 | import org.inventivetalent.npclib.npc.NPCAbstract;
4 |
5 | public class AIAbstract> {
6 |
7 | private N npc;
8 |
9 | /**
10 | * Called when the containing NPC is ticked
11 | */
12 | public void tick() {
13 | }
14 |
15 | /**
16 | * If this returns true
, this AI will be removed from the NPC
17 | *
18 | * @return if true
, the AI will be removed
19 | */
20 | public boolean isFinished() {
21 | return false;
22 | }
23 |
24 | public final N getNpc() {
25 | if (this.npc == null) { throw new IllegalStateException("npc not set"); }
26 | return this.npc;
27 | }
28 |
29 | public final void setNpc(N npc) {
30 | if (this.npc != null) { throw new IllegalStateException("npc already set"); }
31 | this.npc = npc;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/animation/Animation.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.animation;
2 |
3 | public enum Animation {
4 |
5 | SWING_MAIN_ARM(Type.ANIMATION, 0),
6 | TAKE_DAMAGE(Type.ANIMATION, 1),
7 | LEAVE_BED(Type.ANIMATION, 2),
8 | SWING_OFF_HAND(Type.ANIMATION, 3),
9 | CRITICAL_EFFECT(Type.ANIMATION, 4),
10 | CRITICAL_EFFECT_MAGIC(Type.ANIMATION, 5),
11 |
12 | ENTITY_HURT(Type.STATUS, 2),
13 | ENTITY_DEATH(Type.STATUS, 3),
14 | IRON_GOLEM_ARMS(Type.STATUS, 4),
15 | WOLF_SHAKE(Type.STATUS, 8),
16 | SHEEP_EAT(Type.STATUS, 10),
17 | IRON_GOLEM_ROSE(Type.STATUS, 11),
18 | RESET_SQUID_ROTATION(Type.STATUS, 19);
19 |
20 | private final Type type;
21 | private final int id;
22 |
23 | Animation(Type type, int id) {
24 | this.type = type;
25 | this.id = id;
26 | }
27 |
28 | public Type getType() {
29 | return type;
30 | }
31 |
32 | public int getId() {
33 | return id;
34 | }
35 |
36 | public enum Type {
37 | STATUS,
38 | ANIMATION;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/annotation/ExtraMethod.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.annotation;
2 |
3 | import org.inventivetalent.reflection.minecraft.Minecraft;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | @Target(ElementType.METHOD)
11 | @Retention(RetentionPolicy.RUNTIME)
12 | public @interface ExtraMethod {
13 |
14 | String value();
15 |
16 | /**
17 | * If specified, the annotated method will be generate for this version upwards
18 | * @return the Version
19 | */
20 | Minecraft.Version fromVersion() default Minecraft.Version.UNKNOWN;
21 |
22 | /**
23 | * If specified, the annotated method will be generate for this version downwards
24 | * @return the Version
25 | */
26 | Minecraft.Version untilVersion() default Minecraft.Version.UNKNOWN;
27 |
28 | /**
29 | * If specified, the annotated method will be generate for only these versions
30 | * @return the Version
31 | */
32 | Minecraft.Version[] forVersion() default {};
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/annotation/ExtraMethods.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target(ElementType.METHOD)
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface ExtraMethods {
11 | ExtraMethod[] value();
12 | }
13 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/annotation/NPC.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.annotation;
2 |
3 | import org.bukkit.entity.Entity;
4 | import org.bukkit.entity.EntityType;
5 | import org.inventivetalent.npclib.entity.NPCEntity;
6 |
7 | import java.lang.annotation.ElementType;
8 | import java.lang.annotation.Retention;
9 | import java.lang.annotation.RetentionPolicy;
10 | import java.lang.annotation.Target;
11 |
12 | @Retention(RetentionPolicy.RUNTIME)
13 | @Target(ElementType.TYPE)
14 | public @interface NPC {
15 |
16 | int id();
17 |
18 | EntityType type();
19 |
20 | Class extends Entity> bukkit();
21 |
22 | String nms();
23 |
24 | Class extends NPCEntity> entity();
25 |
26 | String[] constructors() default {
27 | "public %1$s(World world){\n"
28 | + " super(world);\n"
29 | + " this.$npc = new %2$s(this);\n"
30 | + "}" };
31 |
32 | String[] extraPackages() default {};
33 |
34 | String[] extraFields() default {};
35 |
36 | String[] extraMethods() default {};
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/annotation/NPCInfo.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.annotation;
2 |
3 | import lombok.*;
4 | import org.bukkit.entity.Entity;
5 | import org.bukkit.entity.EntityType;
6 | import org.inventivetalent.npclib.Reflection;
7 | import org.inventivetalent.npclib.entity.NPCEntity;
8 |
9 | import java.lang.reflect.Modifier;
10 |
11 | import static com.google.common.base.Preconditions.checkArgument;
12 | import static com.google.common.base.Preconditions.checkNotNull;
13 | import static com.google.common.base.Strings.emptyToNull;
14 |
15 | @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
16 | @Data
17 | @EqualsAndHashCode
18 | @ToString
19 | public class NPCInfo {
20 |
21 | private final int id;
22 | private final EntityType type;
23 | private final Class extends Entity> bukkit;
24 | private final String nms;
25 | private final Class extends NPCEntity> entity;
26 | private final String[] constructors;
27 | private final String[] extraPackages;
28 | private final String[] extraFields;
29 | private final String[] extraMethods;
30 | private Class> npcClass;
31 |
32 | public static NPCInfo of(NPC annotation) {
33 | checkNotNull(annotation);
34 | return new NPCInfo(annotation.id(), checkNotNull(annotation.type()), checkNotNull(annotation.bukkit()), checkNotNull(emptyToNull(annotation.nms())), checkNotNull(annotation.entity()), annotation.constructors(), annotation.extraPackages(), annotation.extraFields(), annotation.extraMethods());
35 | }
36 |
37 | public static NPCInfo of(Class> clazz) {
38 | checkNotNull(clazz);
39 | checkArgument(!Modifier.isAbstract(clazz.getModifiers()), "Cannot use @NPC on abstract class");
40 | checkArgument(!clazz.isInterface(), "Cannot use @NPC on interface");
41 | NPC annotation = (NPC) clazz.getAnnotation(NPC.class);
42 | NPCInfo info = of(checkNotNull(annotation, "Class has no @NPC annotation"));
43 | info.npcClass = clazz;
44 | return info;
45 | }
46 |
47 | public Class> getNMSClass() {
48 | try {
49 | return Reflection.nmsClassResolver.resolve(nms);
50 | } catch (ClassNotFoundException e) {
51 | throw new RuntimeException(e);
52 | }
53 | }
54 |
55 | public String getNPCClassName() {
56 | String className = npcClass.getName();
57 | if (className.startsWith("org.inventivetalent.npclib.npc")) {// Internal NPCs
58 | return "NPC" + nms;
59 | } else {
60 | return className.replace(".", "_") + "_NPC";
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/EntityExperienceOrb.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity;
2 |
3 | public interface EntityExperienceOrb extends NPCEntity {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/EntityItem.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity;
2 |
3 | public interface EntityItem extends NPCEntity {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/NPCEntity.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity;
2 |
3 | import org.bukkit.event.entity.CreatureSpawnEvent;
4 | import org.inventivetalent.npclib.annotation.ExtraMethod;
5 | import org.inventivetalent.npclib.annotation.NPCInfo;
6 | import org.inventivetalent.npclib.npc.NPCAbstract;
7 | import org.inventivetalent.npclib.watcher.MethodWatcher;
8 | import org.inventivetalent.reflection.minecraft.Minecraft;
9 | import org.inventivetalent.vectors.d3.Vector3DDouble;
10 |
11 | public interface NPCEntity {
12 |
13 | void setMethodWatcher(MethodWatcher methodWatcher);
14 |
15 | @ExtraMethod("public NPCAbstract getNPC() {\n"
16 | + " return this.$npc;\n"
17 | + "}")
18 | NPCAbstract, ?> getNPC();
19 |
20 | // T getBukkitEntity();
21 |
22 | boolean methodCalled(String name, Object[] args);
23 |
24 | Object methodCalled(String name, Object superValue, Object[] args);
25 |
26 | NPCInfo getNpcInfo();
27 |
28 | void setNpcInfo(NPCInfo npcInfo);
29 |
30 | // Overwritten methods
31 |
32 | void setLocation(double x, double y, double z, float yaw, float pitch);
33 |
34 | // The EnumMoveType was added in 1.11 as an anticheat feature.
35 | @ExtraMethod(value = "public void move(double x, double y, double z) {\n"
36 | + " move(EnumMoveType.SELF, x, y, z);\n"
37 | + "}",
38 | fromVersion = Minecraft.Version.v1_11_R1)
39 | void move(double x, double y, double z);
40 |
41 | // Helpers
42 |
43 | @ExtraMethod("public void spawn() {\n"
44 | + " this.world.addEntity(this);\n"
45 | + "}")
46 | void spawn();
47 |
48 | @ExtraMethod("public void spawn(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {\n"
49 | + " this.world.addEntity(this, spawnReason);\n"
50 | + "}")
51 | void spawn(CreatureSpawnEvent.SpawnReason spawnReason);
52 |
53 | @ExtraMethod("public org.inventivetalent.vectors.d3.Vector3DDouble getLocationVector() {\n"
54 | + " return new org.inventivetalent.vectors.d3.Vector3DDouble(this.locX, this.locY, this.locZ);\n"
55 | + "}")
56 | Vector3DDouble getLocationVector();
57 |
58 | @ExtraMethod("public void setYaw(float yaw) {\n"
59 | + " this.yaw = yaw;\n"
60 | + "}")
61 | void setYaw(float yaw);
62 |
63 | @ExtraMethod("public void setPitch(float pitch) {\n"
64 | + " this.pitch = pitch;\n"
65 | + "}")
66 | void setPitch(float pitch);
67 |
68 | // mot? accessors
69 |
70 | @ExtraMethod("public double getMotX() {"
71 | + " return this.motX;\n"
72 | + "}")
73 | double getMotX();
74 |
75 | @ExtraMethod("public void setMotX(double motX) {\n"
76 | + " this.motX = motX;\n"
77 | + "}")
78 | void setMotX(double motX);
79 |
80 | @ExtraMethod("public double getMotY() {"
81 | + " return this.motY;\n"
82 | + "}")
83 | double getMotY();
84 |
85 | @ExtraMethod("public void setMotY(double motY) {\n"
86 | + " this.motY = motY;\n"
87 | + "}")
88 | void setMotY(double motY);
89 |
90 | @ExtraMethod("public double getMotZ() {"
91 | + " return this.motZ;\n"
92 | + "}")
93 | double getMotZ();
94 |
95 | @ExtraMethod("public void setMotZ(double motZ) {\n"
96 | + " this.motZ = motZ;\n"
97 | + "}")
98 | void setMotZ(double motZ);
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/EntityArmorStand.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living;
2 |
3 | public interface EntityArmorStand extends NPCEntityLiving {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/NPCEntityLiving.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living;
2 |
3 | import org.inventivetalent.npclib.entity.NPCEntity;
4 |
5 | public interface NPCEntityLiving extends NPCEntity {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/human/EntityPlayer.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.human;
2 |
3 | import org.bukkit.event.entity.CreatureSpawnEvent;
4 | import org.inventivetalent.npclib.annotation.ExtraMethod;
5 |
6 | public interface EntityPlayer extends NPCEntityHuman {
7 |
8 | @ExtraMethod("public void spawnPlayer(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {\n"
9 | + " this.world.players.add(this);\n"
10 | + " this.world.entityList.add(this);\n"
11 | + "}")
12 | void spawnPlayer(CreatureSpawnEvent.SpawnReason spawnReason);
13 | }
14 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/human/NPCEntityHuman.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.human;
2 |
3 | import com.mojang.authlib.GameProfile;
4 | import org.inventivetalent.npclib.entity.living.NPCEntityLiving;
5 |
6 | public interface NPCEntityHuman extends NPCEntityLiving {
7 |
8 | GameProfile getProfile();
9 |
10 | void checkMovement(double x, double y, double z);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/EntityEnderDragon.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient;
2 |
3 | public interface EntityEnderDragon extends NPCEntityInsentient {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/EntityPigZombie.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient;
2 |
3 | public interface EntityPigZombie extends EntityZombie {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/EntitySlime.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient;
2 |
3 | public interface EntitySlime extends NPCEntityInsentient {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/EntityZombie.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient;
2 |
3 | public interface EntityZombie extends NPCEntityInsentient {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/NPCEntityInsentient.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient;
2 |
3 | import org.inventivetalent.npclib.entity.living.NPCEntityLiving;
4 |
5 | public interface NPCEntityInsentient extends NPCEntityLiving {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/NPCEntityCreature.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.NPCEntityInsentient;
4 |
5 | public interface NPCEntityCreature extends NPCEntityInsentient {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/EntityVillager.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable;
2 |
3 | public interface EntityVillager extends NPCEntityAgeable {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/NPCEntityAgeable.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.creature.NPCEntityCreature;
4 |
5 | public interface NPCEntityAgeable extends NPCEntityCreature {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityChicken.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityChicken extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityCow.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityCow extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityHorse.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityHorse extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityLlama.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityLlama extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityMushroomCow.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityMushroomCow extends EntityCow {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityPig.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityPig extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityPolarBear.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityPolarBear extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntityRabbit.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntityRabbit extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/EntitySheep.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | public interface EntitySheep extends NPCEntityAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/NPCEntityAnimal.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.creature.ageable.NPCEntityAgeable;
4 |
5 | public interface NPCEntityAnimal extends NPCEntityAgeable {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/tameable/EntityOcelot.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal.tameable;
2 |
3 | public interface EntityOcelot extends NPCEntityTameable {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/tameable/EntityWolf.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal.tameable;
2 |
3 | public interface EntityWolf extends NPCEntityTameable {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/ageable/animal/tameable/NPCEntityTameable.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal.tameable;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.creature.ageable.animal.NPCEntityAnimal;
4 |
5 | public interface NPCEntityTameable extends NPCEntityAnimal {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/golem/EntityIronGolem.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.golem;
2 |
3 | public interface EntityIronGolem extends NPCEntityGolem {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/golem/EntityShulker.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.golem;
2 |
3 | public interface EntityShulker extends NPCEntityGolem {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/golem/EntitySnowman.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.golem;
2 |
3 | public interface EntitySnowman extends NPCEntityGolem {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/golem/NPCEntityGolem.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.golem;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.creature.NPCEntityCreature;
4 |
5 | public interface NPCEntityGolem extends NPCEntityCreature {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityCaveSpider.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityCaveSpider extends EntitySpider {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityCreeper.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityCreeper extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityEnderman.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityEnderman extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityEndermite.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityEndermite extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityGiant.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityGiant extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityGuardian.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityGuardian extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityHusk.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.EntityZombie;
4 |
5 | public interface EntityHusk extends EntityZombie {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntitySkeleton.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntitySkeleton extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntitySpider.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntitySpider extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityWitch.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityWitch extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/EntityWither.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | public interface EntityWither extends NPCEntityMonster {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/creature/monster/NPCEntityMonster.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.creature.monster;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.creature.NPCEntityCreature;
4 |
5 | public interface NPCEntityMonster extends NPCEntityCreature {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/flying/EntityGhast.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.flying;
2 |
3 | public interface EntityGhast extends NPCEntityFlying {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/flying/NPCEntityFlying.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.flying;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.NPCEntityInsentient;
4 |
5 | public interface NPCEntityFlying extends NPCEntityInsentient {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/water/EntitySquid.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.water;
2 |
3 | public interface EntitySquid extends NPCEntityWaterAnimal {
4 | }
5 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/entity/living/insentient/water/NPCEntityWaterAnimal.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.entity.living.insentient.water;
2 |
3 | import org.inventivetalent.npclib.entity.living.insentient.NPCEntityInsentient;
4 |
5 | public interface NPCEntityWaterAnimal extends NPCEntityInsentient {
6 | }
7 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/equipment/EquipmentSlot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.equipment;
30 |
31 | import org.inventivetalent.npclib.Reflection;
32 | import org.inventivetalent.reflection.minecraft.Minecraft;
33 |
34 | public enum EquipmentSlot {
35 |
36 | @Deprecated HAND(0),
37 | MAIN_HAND(0),
38 | OFF_HAND(1),
39 | FEET(2),
40 | LEGS(3),
41 | CHEST(4),
42 | HEAD(5);
43 |
44 | private int id;
45 |
46 | EquipmentSlot(int id) {
47 | this.id = id;
48 | }
49 |
50 | public int getID() {
51 | if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1)) {
52 | return this.id;
53 | } else {
54 | switch (this) {
55 | case OFF_HAND:
56 | return 0;
57 | case FEET:
58 | return 1;
59 | case LEGS:
60 | return 2;
61 | case CHEST:
62 | return 3;
63 | case HEAD:
64 | return 4;
65 | default:
66 | return this.id;
67 | }
68 | }
69 | }
70 |
71 | public Object toNMS() {
72 | if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1)) {
73 | try {
74 | return Reflection.nmsClassResolver.resolve("EnumItemSlot").getEnumConstants()[this.id];
75 | } catch (ClassNotFoundException e) {
76 | throw new RuntimeException(e);
77 | }
78 | } else if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_8_R1)) {
79 | return getID();
80 | } else {
81 | return null;
82 | }
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/NPCCollisionEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.event;
30 |
31 | import org.bukkit.entity.Entity;
32 | import org.bukkit.event.HandlerList;
33 | import org.inventivetalent.npclib.npc.NPCAbstract;
34 |
35 | public class NPCCollisionEvent extends NPCEvent {
36 |
37 | private Entity entity;
38 |
39 | public NPCCollisionEvent(NPCAbstract, ?> npc, Entity with) {
40 | super(npc);
41 | this.entity = with;
42 | }
43 |
44 | public Entity getEntity() {
45 | return entity;
46 | }
47 |
48 | private static HandlerList handlerList = new HandlerList();
49 |
50 | @Override
51 | public HandlerList getHandlers() {
52 | return handlerList;
53 | }
54 |
55 | public static HandlerList getHandlerList() {
56 | return handlerList;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/NPCDamageEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.event;
30 |
31 | import org.bukkit.entity.Entity;
32 | import org.bukkit.event.Cancellable;
33 | import org.bukkit.event.HandlerList;
34 | import org.bukkit.event.entity.EntityDamageEvent;
35 | import org.inventivetalent.npclib.npc.NPCAbstract;
36 |
37 | import javax.annotation.Nullable;
38 |
39 | /**
40 | * Called if an NPC is damaged
41 | */
42 | public class NPCDamageEvent extends NPCEvent implements Cancellable {
43 |
44 | private static HandlerList handlerList = new HandlerList();
45 | private boolean cancelled;
46 | private String damageSourceName;
47 | private EntityDamageEvent.DamageCause damageCause;
48 | private float amount;
49 | private Entity damager;
50 |
51 | public NPCDamageEvent(NPCAbstract, ?> npc, String damageSourceName, EntityDamageEvent.DamageCause damageCause,
52 | float amount, Entity damager) {
53 | super(npc);
54 |
55 | this.damageSourceName = damageSourceName;
56 | this.damageCause = damageCause;
57 | this.amount = amount;
58 | this.damager = damager;
59 | }
60 |
61 | public static HandlerList getHandlerList() {
62 | return handlerList;
63 | }
64 |
65 | /**
66 | * Get the NMS damage source name
67 | *
68 | * @return the source name
69 | */
70 | public String getDamageSourceName() {
71 | return damageSourceName;
72 | }
73 |
74 | /**
75 | * Get the damage cause
76 | *
77 | * @return the event's {@link org.bukkit.event.entity.EntityDamageEvent.DamageCause}
78 | */
79 | public EntityDamageEvent.DamageCause getDamageCause() {
80 | return damageCause;
81 | }
82 |
83 | /**
84 | * Get the amount
85 | *
86 | * @return the damage amount
87 | */
88 | public float getAmount() {
89 | return amount;
90 | }
91 |
92 | /**
93 | * Set the amount
94 | *
95 | * @param amount the new damage amount
96 | */
97 | public void setAmount(float amount) {
98 | this.amount = amount;
99 | }
100 |
101 | /**
102 | * Get the damager
103 | *
104 | * @return the entity that damaged the NPC, or null
105 | */
106 | @Nullable
107 | public Entity getDamager() {
108 | return damager;
109 | }
110 |
111 | @Override
112 | public boolean isCancelled() {
113 | return cancelled;
114 | }
115 |
116 | @Override
117 | public void setCancelled(boolean b) {
118 | cancelled = b;
119 | }
120 |
121 | @Override
122 | public HandlerList getHandlers() {
123 | return handlerList;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/NPCDeathEvent.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.event;
2 |
3 | import org.bukkit.event.Cancellable;
4 | import org.bukkit.event.HandlerList;
5 | import org.bukkit.event.entity.EntityDamageEvent;
6 | import org.inventivetalent.npclib.npc.NPCAbstract;
7 |
8 | /**
9 | * Event called when a NPC dies.
10 | *
11 | * Note: This event is called twice for living entities. Once for the LivingEntity with a damage source, once for the base entity without a source.
12 | */
13 | public class NPCDeathEvent extends NPCEvent implements Cancellable {
14 |
15 | private static HandlerList handlerList = new HandlerList();
16 | private boolean cancelled;
17 | private String damageSourceName;
18 | private EntityDamageEvent.DamageCause damageCause;
19 |
20 | public NPCDeathEvent(NPCAbstract, ?> npc, String damageSourceName, EntityDamageEvent.DamageCause damageCause) {
21 | super(npc);
22 | this.damageSourceName = damageSourceName;
23 | this.damageCause = damageCause;
24 | }
25 |
26 | public static HandlerList getHandlerList() {
27 | return handlerList;
28 | }
29 |
30 | /**
31 | * Whether this death event has a source. Always false
for non-living entities
32 | *
33 | * @return true
if the death has a source
34 | */
35 | public boolean hasSource() {
36 | return damageSourceName != null;
37 | }
38 |
39 | /**
40 | * Get the damage source name
41 | *
42 | * @return the source name
43 | */
44 | public String getDamageSourceName() {
45 | return damageSourceName;
46 | }
47 |
48 | /**
49 | * Get the damage cause
50 | *
51 | * @return the {@link org.bukkit.event.entity.EntityDamageEvent.DamageCause}
52 | */
53 | public EntityDamageEvent.DamageCause getDamageCause() {
54 | return damageCause;
55 | }
56 |
57 | @Override
58 | public boolean isCancelled() {
59 | return cancelled;
60 | }
61 |
62 | @Override
63 | public void setCancelled(boolean b) {
64 | cancelled = b;
65 | }
66 |
67 | @Override
68 | public HandlerList getHandlers() {
69 | return handlerList;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/NPCEvent.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.event;
2 |
3 | import org.bukkit.entity.EntityType;
4 | import org.bukkit.event.Event;
5 | import org.inventivetalent.npclib.NPCType;
6 | import org.inventivetalent.npclib.npc.NPCAbstract;
7 |
8 | /**
9 | * Abstract base class for NPC events
10 | */
11 | public abstract class NPCEvent extends Event {
12 |
13 | private final NPCAbstract, ?> npc;
14 |
15 | public NPCEvent(NPCAbstract, ?> npc) {
16 | this.npc = npc;
17 | }
18 |
19 | /**
20 | * Get the involved NPC
21 | *
22 | * @return the NPC
23 | */
24 | public NPCAbstract, ?> getNpc() {
25 | return npc;
26 | }
27 |
28 | /**
29 | * Get the NPC's type
30 | *
31 | * @return the {@link NPCType}
32 | */
33 | public NPCType getNpcType() {
34 | return npc.getNpcType();
35 | }
36 |
37 | /**
38 | * Get the NPC's entity type
39 | *
40 | * @return the {@link EntityType}
41 | */
42 | public EntityType getEntityType() {
43 | return npc.getEntityType();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/NPCInteractEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.event;
30 |
31 | import org.bukkit.entity.Player;
32 | import org.bukkit.event.Cancellable;
33 | import org.bukkit.event.HandlerList;
34 | import org.inventivetalent.npclib.npc.NPCAbstract;
35 |
36 | public class NPCInteractEvent extends NPCEvent implements Cancellable {
37 |
38 | private static HandlerList handlerList = new HandlerList();
39 | private int entityId;
40 | private int actionId;
41 | private Player player;
42 | private boolean cancelled;
43 |
44 | public NPCInteractEvent(NPCAbstract, ?> npc, int entityId, int actionId, Player player) {
45 | super(npc);
46 | this.entityId = entityId;
47 | this.actionId = actionId;
48 | this.player = player;
49 | }
50 |
51 | public static HandlerList getHandlerList() {
52 | return handlerList;
53 | }
54 |
55 | public int getEntityId() {
56 | return entityId;
57 | }
58 |
59 | public int getActionId() {
60 | return actionId;
61 | }
62 |
63 | public Player getPlayer() {
64 | return player;
65 | }
66 |
67 | @Override
68 | public boolean isCancelled() {
69 | return cancelled;
70 | }
71 |
72 | @Override
73 | public void setCancelled(boolean b) {
74 | cancelled = b;
75 | }
76 |
77 | @Override
78 | public HandlerList getHandlers() {
79 | return handlerList;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/NPCSpawnEvent.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.event;
2 |
3 | import com.google.common.base.Preconditions;
4 | import org.bukkit.Location;
5 | import org.bukkit.event.HandlerList;
6 | import org.bukkit.event.entity.CreatureSpawnEvent;
7 | import org.inventivetalent.npclib.npc.NPCAbstract;
8 |
9 | import javax.annotation.Nonnull;
10 |
11 | /**
12 | * Event called when a new NPC is spawned
13 | */
14 | public class NPCSpawnEvent extends NPCEvent {
15 |
16 | private static HandlerList handlerList = new HandlerList();
17 | private CreatureSpawnEvent.SpawnReason spawnReason;
18 |
19 | public NPCSpawnEvent(NPCAbstract, ?> npc, CreatureSpawnEvent.SpawnReason spawnReason) {
20 | super(npc);
21 | this.spawnReason = spawnReason;
22 | }
23 |
24 | public static HandlerList getHandlerList() {
25 | return handlerList;
26 | }
27 |
28 | /**
29 | * Get the location where the NPC was spawned
30 | *
31 | * @return the spawn {@link Location}
32 | */
33 | public Location getLocation() {
34 | return getNpc().getBukkitEntity().getLocation();
35 | }
36 |
37 | /**
38 | * Get the spawn reason
39 | *
40 | * @return the {@link org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason}
41 | */
42 | public CreatureSpawnEvent.SpawnReason getSpawnReason() {
43 | return spawnReason;
44 | }
45 |
46 | /**
47 | * Set the spawn reason
48 | *
49 | * @param spawnReason the new spawn reason
50 | */
51 | public void setSpawnReason(@Nonnull CreatureSpawnEvent.SpawnReason spawnReason) {
52 | Preconditions.checkNotNull(spawnReason);
53 | this.spawnReason = spawnReason;
54 | }
55 |
56 | @Override
57 | public HandlerList getHandlers() {
58 | return handlerList;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/NPCVelocityEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.event;
30 |
31 | import org.bukkit.event.Cancellable;
32 | import org.bukkit.event.HandlerList;
33 | import org.inventivetalent.npclib.npc.NPCAbstract;
34 |
35 | public class NPCVelocityEvent extends NPCEvent implements Cancellable {
36 |
37 | private boolean cancelled;
38 | private double x;
39 | private double y;
40 | private double z;
41 |
42 | public NPCVelocityEvent(NPCAbstract, ?> npc, double x, double y, double z) {
43 | super(npc);
44 | this.x = x;
45 | this.y = y;
46 | this.z = z;
47 | }
48 |
49 | public double getX() {
50 | return x;
51 | }
52 |
53 | public void setX(double x) {
54 | this.x = x;
55 | }
56 |
57 | public double getY() {
58 | return y;
59 | }
60 |
61 | public void setY(double y) {
62 | this.y = y;
63 | }
64 |
65 | public double getZ() {
66 | return z;
67 | }
68 |
69 | public void setZ(double z) {
70 | this.z = z;
71 | }
72 |
73 | @Override
74 | public boolean isCancelled() {
75 | return cancelled;
76 | }
77 |
78 | @Override
79 | public void setCancelled(boolean b) {
80 | cancelled = b;
81 | }
82 |
83 | private static HandlerList handlerList = new HandlerList();
84 |
85 | @Override
86 | public HandlerList getHandlers() {
87 | return handlerList;
88 | }
89 |
90 | public static HandlerList getHandlerList() {
91 | return handlerList;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/nbt/NBTReadEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.event.nbt;
30 |
31 | import org.bukkit.event.HandlerList;
32 | import org.inventivetalent.nbt.CompoundTag;
33 | import org.inventivetalent.npclib.npc.NPCAbstract;
34 |
35 | public class NBTReadEvent extends NPCNBTEvent {
36 |
37 | private static HandlerList handlerList = new HandlerList();
38 |
39 | public NBTReadEvent(NPCAbstract, ?> npc, Object nbtTagHandle, CompoundTag nbtTag) {
40 | super(npc, nbtTagHandle, nbtTag);
41 | }
42 |
43 | public static HandlerList getHandlerList() {
44 | return handlerList;
45 | }
46 |
47 | @Override
48 | public CompoundTag getNbtTag() {
49 | return (CompoundTag) super.getNbtTag();
50 | }
51 |
52 | @Override
53 | public HandlerList getHandlers() {
54 | return handlerList;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/nbt/NBTWriteEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.event.nbt;
30 |
31 | import org.bukkit.event.HandlerList;
32 | import org.inventivetalent.nbt.CompoundTag;
33 | import org.inventivetalent.npclib.npc.NPCAbstract;
34 |
35 | public class NBTWriteEvent extends NPCNBTEvent {
36 |
37 | private static HandlerList handlerList = new HandlerList();
38 |
39 | public NBTWriteEvent(NPCAbstract, ?> npc, Object nbtTagHandle, CompoundTag nbtTag) {
40 | super(npc, nbtTagHandle, nbtTag);
41 | }
42 |
43 | public static HandlerList getHandlerList() {
44 | return handlerList;
45 | }
46 |
47 | @Override
48 | public CompoundTag getNbtTag() {
49 | return (CompoundTag) super.getNbtTag();
50 | }
51 |
52 | @Override
53 | public HandlerList getHandlers() {
54 | return handlerList;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/nbt/NPCNBTEvent.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.event.nbt;
2 |
3 | import org.inventivetalent.nbt.NBTTag;
4 | import org.inventivetalent.npclib.event.NPCEvent;
5 | import org.inventivetalent.npclib.npc.NPCAbstract;
6 |
7 | public abstract class NPCNBTEvent extends NPCEvent {
8 |
9 | private final Object nbtTagHandle;
10 | private final NBTTag> nbtTag;
11 |
12 | public NPCNBTEvent(NPCAbstract, ?> npc, Object nbtTagHandle, NBTTag> nbtTag) {
13 | super(npc);
14 | this.nbtTagHandle = nbtTagHandle;
15 | this.nbtTag = nbtTag;
16 | }
17 |
18 | public Object getNbtTagHandle() {
19 | return nbtTagHandle;
20 | }
21 |
22 | public NBTTag> getNbtTag() {
23 | return nbtTag;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/event/path/NPCPathFinishEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.npclib.event.path;
30 |
31 | import org.bukkit.event.HandlerList;
32 | import org.inventivetalent.npclib.event.NPCEvent;
33 | import org.inventivetalent.npclib.npc.NPCAbstract;
34 |
35 | public class NPCPathFinishEvent extends NPCEvent {
36 |
37 | public NPCPathFinishEvent(NPCAbstract, ?> npc) {
38 | super(npc);
39 | }
40 |
41 | private static HandlerList handlerList = new HandlerList();
42 |
43 | @Override
44 | public HandlerList getHandlers() {
45 | return handlerList;
46 | }
47 |
48 | public static HandlerList getHandlerList() {
49 | return handlerList;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/npc/NPCExperienceOrb.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.npc;
2 |
3 | import org.bukkit.entity.EntityType;
4 | import org.bukkit.entity.ExperienceOrb;
5 | import org.inventivetalent.npclib.annotation.NPC;
6 | import org.inventivetalent.npclib.entity.EntityExperienceOrb;
7 |
8 | @NPC(id = 2,
9 | type = EntityType.EXPERIENCE_ORB,
10 | bukkit = ExperienceOrb.class,
11 | nms = "EntityExperienceOrb",
12 | entity = EntityExperienceOrb.class)
13 | public class NPCExperienceOrb extends NPCAbstract {
14 | public NPCExperienceOrb(EntityExperienceOrb npcEntity) {
15 | super(npcEntity);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/npc/NPCItem.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.npc;
2 |
3 | import org.bukkit.entity.EntityType;
4 | import org.bukkit.entity.Item;
5 | import org.inventivetalent.npclib.annotation.NPC;
6 | import org.inventivetalent.npclib.entity.EntityItem;
7 |
8 | @NPC(id = 1,
9 | type = EntityType.DROPPED_ITEM,
10 | bukkit = Item.class,
11 | nms = "EntityItem",
12 | entity = EntityItem.class)
13 | public class NPCItem extends NPCAbstract {
14 | public NPCItem(EntityItem npcEntity) {
15 | super(npcEntity);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/npc/living/NPCArmorStand.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.npc.living;
2 |
3 | import org.bukkit.entity.ArmorStand;
4 | import org.bukkit.entity.EntityType;
5 | import org.inventivetalent.npclib.annotation.NPC;
6 | import org.inventivetalent.npclib.entity.living.EntityArmorStand;
7 |
8 | @NPC(id = 30,
9 | type = EntityType.ARMOR_STAND,
10 | bukkit = ArmorStand.class,
11 | nms = "EntityArmorStand",
12 | entity = EntityArmorStand.class)
13 | public class NPCArmorStand extends NPCLivingAbstract {
14 | public NPCArmorStand(EntityArmorStand npcEntity) {
15 | super(npcEntity);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/API/src/main/java/org/inventivetalent/npclib/npc/living/NPCLivingAbstract.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.npclib.npc.living;
2 |
3 | import com.google.common.base.Predicate;
4 | import org.bukkit.Bukkit;
5 | import org.bukkit.entity.LivingEntity;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.entity.EntityDamageEvent;
8 | import org.bukkit.inventory.ItemStack;
9 | import org.inventivetalent.npclib.ObjectContainer;
10 | import org.inventivetalent.npclib.Reflection;
11 | import org.inventivetalent.npclib.SuperSwitch;
12 | import org.inventivetalent.npclib.entity.living.NPCEntityLiving;
13 | import org.inventivetalent.npclib.equipment.EquipmentSlot;
14 | import org.inventivetalent.npclib.event.NPCDeathEvent;
15 | import org.inventivetalent.npclib.event.path.NPCPathFinishEvent;
16 | import org.inventivetalent.npclib.npc.NPCAbstract;
17 | import org.inventivetalent.npclib.path.AStarPathfinder;
18 | import org.inventivetalent.npclib.path.PathfinderAbstract;
19 | import org.inventivetalent.npclib.watcher.Watch;
20 | import org.inventivetalent.reflection.minecraft.Minecraft;
21 | import org.inventivetalent.reflection.resolver.FieldResolver;
22 | import org.inventivetalent.reflection.resolver.MethodResolver;
23 | import org.inventivetalent.reflection.resolver.ResolverQuery;
24 | import org.inventivetalent.vectors.d3.Vector3DDouble;
25 |
26 | import javax.annotation.Nullable;
27 |
28 | import java.lang.reflect.Constructor;
29 |
30 | public abstract class NPCLivingAbstract extends NPCAbstract {
31 |
32 | // The static code gets run once, saves resources.
33 | protected static FieldResolver entityLivingFieldResolver = new FieldResolver(Reflection.nmsClassResolver.resolveSilent("EntityLiving"));
34 | protected static MethodResolver entityLivingMethodResolver = new MethodResolver(Reflection.nmsClassResolver.resolveSilent("EntityLiving"));
35 |
36 | private PathfinderAbstract pathfinder;
37 |
38 | public NPCLivingAbstract(N npcEntity) {
39 | super(npcEntity);
40 | }
41 |
42 | @Watch("void die(DamageSource)")
43 | public void onDie(ObjectContainer