Commits
Mikołaj Nowak authored and md_5 committed ab74003f431
1 1 | package org.bukkit.entity; |
2 2 | |
3 3 | import com.google.common.base.Preconditions; |
4 4 | import com.google.common.collect.Lists; |
5 5 | import java.util.Locale; |
6 + | import java.util.UUID; |
7 + | import org.bukkit.Bukkit; |
6 8 | import org.bukkit.Keyed; |
7 9 | import org.bukkit.Location; |
8 10 | import org.bukkit.NamespacedKey; |
9 11 | import org.bukkit.Registry; |
10 12 | import org.bukkit.util.OldEnum; |
11 13 | import org.jetbrains.annotations.NotNull; |
12 14 | import org.jetbrains.annotations.Nullable; |
13 15 | |
14 16 | /** |
15 17 | * Represents a villager NPC |
111 113 | * Zombie. |
112 114 | * |
113 115 | * <b>Note:</b> this will fire a EntityTransformEvent |
114 116 | * |
115 117 | * @return the converted entity {@link ZombieVillager} or null if the |
116 118 | * conversion its cancelled |
117 119 | */ |
118 120 | |
119 121 | public ZombieVillager zombify(); |
120 122 | |
123 + | /** |
124 + | * Gets the reputation of an entity for a given type. |
125 + | * |
126 + | * @param uuid the UUID of the entity whose reputation is being checked |
127 + | * @param reputationType reputation type to be retrieved |
128 + | * @return current reputation for the given reputation type |
129 + | */ |
130 + | public int getReputation( UUID uuid, ReputationType reputationType); |
131 + | |
132 + | /** |
133 + | * Gets the weighted reputation of an entity for a given type. |
134 + | * |
135 + | * <p>The total reputation of an entity is a sum of its weighted |
136 + | * reputations of each type, where the reputation is multiplied by weight |
137 + | * assigned to its type. |
138 + | * |
139 + | * @param uuid the UUID of the entity whose reputation is being checked |
140 + | * @param reputationType reputation type to be retrieved |
141 + | * @return current reputation for the given reputation type |
142 + | * @see ReputationType#getWeight() |
143 + | */ |
144 + | public int getWeightedReputation( UUID uuid, ReputationType reputationType); |
145 + | |
146 + | /** |
147 + | * Gets the reputation of an entity. |
148 + | * |
149 + | * @param uuid the UUID of the entity whose reputation is being checked |
150 + | * @return current reputation for the given reputation type |
151 + | */ |
152 + | public int getReputation( UUID uuid); |
153 + | |
154 + | /** |
155 + | * Add reputation of a given type towards a given entity. |
156 + | * |
157 + | * <p>The final value will be clamped to the maximum value supported by the |
158 + | * provided reputation type. If the final value is below the reputation |
159 + | * discard threshold, gossip associated with this reputation type will be |
160 + | * removed. |
161 + | * |
162 + | * <p>Note: this will fire a |
163 + | * {@link org.bukkit.event.entity.VillagerReputationChangeEvent}. |
164 + | * |
165 + | * @param uuid the UUID of the entity for whom the reputation is being |
166 + | * added |
167 + | * @param reputationType reputation type to be modified |
168 + | * @param amount amount of reputation to add |
169 + | */ |
170 + | public void addReputation( UUID uuid, ReputationType reputationType, int amount); |
171 + | |
172 + | /** |
173 + | * Add reputation of a given type towards a given entity, with a specific |
174 + | * change reason. |
175 + | * |
176 + | * <p>The final value will be clamped to the maximum value supported by the |
177 + | * provided reputation type. If the final value is below the reputation |
178 + | * discard threshold, gossip associated with this reputation type will be |
179 + | * removed. |
180 + | * |
181 + | * <p>Note: this will fire a |
182 + | * {@link org.bukkit.event.entity.VillagerReputationChangeEvent}. |
183 + | * |
184 + | * @param uuid the UUID of the entity for whom the reputation is being |
185 + | * added |
186 + | * @param reputationType reputation type to be modified |
187 + | * @param amount amount of reputation to add |
188 + | * @param changeReason reputation change reason |
189 + | */ |
190 + | public void addReputation( UUID uuid, ReputationType reputationType, int amount, ReputationEvent changeReason); |
191 + | |
192 + | /** |
193 + | * Remove reputation of a given type towards a given entity. |
194 + | * |
195 + | * <p>The final value will be clamped to the maximum value supported by the |
196 + | * provided reputation type. If the final value is below the reputation |
197 + | * discard threshold, gossip associated with this reputation type will be |
198 + | * removed. |
199 + | * |
200 + | * <p>Note: this will fire a |
201 + | * {@link org.bukkit.event.entity.VillagerReputationChangeEvent}. |
202 + | * |
203 + | * @param uuid the UUID of the entity for whom the reputation is being |
204 + | * removed |
205 + | * @param reputationType reputation type to be modified |
206 + | * @param amount amount of reputation to remove |
207 + | */ |
208 + | public void removeReputation( UUID uuid, ReputationType reputationType, int amount); |
209 + | |
210 + | /** |
211 + | * Remove reputation of a given type towards a given entity, with a |
212 + | * specific change reason. |
213 + | * |
214 + | * <p>The final value will be clamped to the maximum value supported by the |
215 + | * provided reputation type. If the final value is below the reputation |
216 + | * discard threshold, gossip associated with this reputation type will be |
217 + | * removed. |
218 + | * |
219 + | * <p>Note: this will fire a |
220 + | * {@link org.bukkit.event.entity.VillagerReputationChangeEvent}. |
221 + | * |
222 + | * @param uuid the UUID of the entity for whom the reputation is being |
223 + | * removed |
224 + | * @param reputationType reputation type to be modified |
225 + | * @param amount amount of reputation to remove |
226 + | * @param changeReason reputation change reason |
227 + | */ |
228 + | public void removeReputation( UUID uuid, ReputationType reputationType, int amount, ReputationEvent changeReason); |
229 + | |
230 + | /** |
231 + | * Set reputation of a given type towards a given entity. |
232 + | * |
233 + | * <p>The final value will be clamped to the maximum value supported by the |
234 + | * provided reputation type. If the final value is below the reputation |
235 + | * discard threshold, gossip associated with this reputation type will be |
236 + | * removed. |
237 + | * |
238 + | * <p>Note: this will fire a |
239 + | * {@link org.bukkit.event.entity.VillagerReputationChangeEvent}. |
240 + | * |
241 + | * @param uuid the UUID of the entity for whom the reputation is being |
242 + | * added |
243 + | * @param reputationType reputation type to be modified |
244 + | * @param amount amount of reputation to add |
245 + | */ |
246 + | public void setReputation( UUID uuid, ReputationType reputationType, int amount); |
247 + | |
248 + | /** |
249 + | * Set reputation of a given type towards a given entity, with a specific |
250 + | * change reason. |
251 + | * |
252 + | * <p>The final value will be clamped to the maximum value supported by the |
253 + | * provided reputation type. If the final value is below the reputation |
254 + | * discard threshold, gossip associated with this reputation type will be |
255 + | * removed. |
256 + | * |
257 + | * <p>Note: this will fire a |
258 + | * {@link org.bukkit.event.entity.VillagerReputationChangeEvent}. |
259 + | * |
260 + | * @param uuid the UUID of the entity for whom the reputation is being |
261 + | * added |
262 + | * @param reputationType reputation type to be modified |
263 + | * @param amount amount of reputation to add |
264 + | * @param changeReason reputation change reason |
265 + | */ |
266 + | public void setReputation( UUID uuid, ReputationType reputationType, int amount, ReputationEvent changeReason); |
267 + | |
268 + | /** |
269 + | * Sets the reputation decay time for this villager. |
270 + | * |
271 + | * <p>Defaults to <b>24000</b> (1 daylight cycle). |
272 + | * |
273 + | * @param ticks amount of ticks until the villager's reputation decays |
274 + | */ |
275 + | public void setGossipDecayTime(long ticks); |
276 + | |
277 + | /** |
278 + | * Gets the reputation decay time for this villager. |
279 + | * |
280 + | * <p>Defaults to <b>24000</b> (1 daylight cycle). |
281 + | * |
282 + | * @return amount of ticks until the villager's reputation decays |
283 + | */ |
284 + | public long getGossipDecayTime(); |
285 + | |
121 286 | /** |
122 287 | * Represents Villager type, usually corresponding to what biome they spawn |
123 288 | * in. |
124 289 | */ |
125 290 | interface Type extends OldEnum<Type>, Keyed { |
126 291 | |
127 292 | Type DESERT = getType("desert"); |
128 293 | Type JUNGLE = getType("jungle"); |
129 294 | Type PLAINS = getType("plains"); |
130 295 | Type SAVANNA = getType("savanna"); |
260 425 | /** |
261 426 | * @return an array of all known villager professions. |
262 427 | * @deprecated use {@link Registry#iterator()}. |
263 428 | */ |
264 429 | |
265 430 | since = "1.21") | (
266 431 | static Profession[] values() { |
267 432 | return Lists.newArrayList(Registry.VILLAGER_PROFESSION).toArray(new Profession[0]); |
268 433 | } |
269 434 | } |
435 + | |
436 + | /** |
437 + | * Reputation type used in gossips. |
438 + | */ |
439 + | interface ReputationType { |
440 + | |
441 + | /** |
442 + | * Major negative reputation. It is caused by killing a villager. |
443 + | */ |
444 + | ReputationType MAJOR_NEGATIVE = getReputationType("major_negative"); |
445 + | /** |
446 + | * Minor negative reputation. It is caused by attacking a villager. |
447 + | */ |
448 + | ReputationType MINOR_NEGATIVE = getReputationType("minor_negative"); |
449 + | /** |
450 + | * Minor positive reputation. It is caused by curing a villager. |
451 + | */ |
452 + | ReputationType MINOR_POSITIVE = getReputationType("minor_positive"); |
453 + | /** |
454 + | * Major positive reputation. It is caused by curing a villager, it is |
455 + | * never shared in gossip and never decays. |
456 + | */ |
457 + | ReputationType MAJOR_POSITIVE = getReputationType("major_positive"); |
458 + | /** |
459 + | * Trading reputation. It has the same weight as minor positive |
460 + | * reputation and is caused by trading with a villager. |
461 + | */ |
462 + | ReputationType TRADING = getReputationType("trading"); |
463 + | |
464 + | /** |
465 + | * Get maximum reputation value of this type. |
466 + | * @return maximum value of this reputation type |
467 + | */ |
468 + | int getMaxValue(); |
469 + | |
470 + | /** |
471 + | * Get weight of this reputation type. |
472 + | * |
473 + | * <p>When calculating total reputation of an entity, reputation of |
474 + | * each type is multiplied by its weight. |
475 + | * |
476 + | * @return weight assigned to this reputation type |
477 + | */ |
478 + | int getWeight(); |
479 + | |
480 + | private static ReputationType getReputationType(String key) { |
481 + | return Bukkit.getUnsafe().createReputationType(key); |
482 + | } |
483 + | } |
484 + | |
485 + | /** |
486 + | * Reputation change reason. |
487 + | */ |
488 + | interface ReputationEvent { |
489 + | |
490 + | /** |
491 + | * A villager was cured by a player. |
492 + | */ |
493 + | ReputationEvent ZOMBIE_VILLAGER_CURED = getReputationEvent("zombie_villager_cured"); |
494 + | /** |
495 + | * A player traded with a villager. |
496 + | */ |
497 + | ReputationEvent TRADE = getReputationEvent("trade"); |
498 + | /** |
499 + | * A villager was hurt by an entity. |
500 + | */ |
501 + | ReputationEvent VILLAGER_HURT = getReputationEvent("villager_hurt"); |
502 + | /** |
503 + | * A villager was killed by an entity. |
504 + | */ |
505 + | ReputationEvent VILLAGER_KILLED = getReputationEvent("villager_killed"); |
506 + | /** |
507 + | * A villager gossiped with another villager. |
508 + | */ |
509 + | ReputationEvent GOSSIP = getReputationEvent("bukkit_gossip"); |
510 + | /** |
511 + | * Reputation decayed over time. |
512 + | */ |
513 + | ReputationEvent DECAY = getReputationEvent("bukkit_decay"); |
514 + | /** |
515 + | * Village's iron golem was killed by an entity. |
516 + | */ |
517 + | ReputationEvent GOLEM_KILLED = getReputationEvent("golem_killed"); |
518 + | /** |
519 + | * Unspecified reason. Available only by setting the reputation |
520 + | * programmatically. |
521 + | */ |
522 + | ReputationEvent UNSPECIFIED = getReputationEvent("bukkit_unspecified"); |
523 + | |
524 + | private static ReputationEvent getReputationEvent(String key) { |
525 + | return Bukkit.getUnsafe().createReputationEvent(key); |
526 + | } |
527 + | } |
270 528 | } |