13
0
geforkt von Mirrors/Paper
Paper/patches/api/0188-Add-villager-reputation-API.patch

175 Zeilen
6.6 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Wed, 22 Apr 2020 23:13:49 +0200
Subject: [PATCH] Add villager reputation API
diff --git a/src/main/java/com/destroystokyo/paper/entity/villager/Reputation.java b/src/main/java/com/destroystokyo/paper/entity/villager/Reputation.java
new file mode 100644
index 0000000000000000000000000000000000000000..cbbf70507c2df922e75b686c36500f6f85f92db6
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/villager/Reputation.java
@@ -0,0 +1,56 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.entity.villager;
+
+import com.google.common.base.Preconditions;
+import java.util.EnumMap;
2021-06-11 14:02:28 +02:00
+import java.util.Map;
+import org.jspecify.annotations.NullMarked;
2021-06-11 14:02:28 +02:00
+
+/**
+ * A reputation score for a player on a villager.
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public final class Reputation {
+
+ private final Map<ReputationType, Integer> reputation;
2021-06-11 14:02:28 +02:00
+
+ public Reputation() {
+ this(new EnumMap<>(ReputationType.class));
2021-06-11 14:02:28 +02:00
+ }
+
+ public Reputation(final Map<ReputationType, Integer> reputation) {
2021-06-11 14:02:28 +02:00
+ Preconditions.checkNotNull(reputation, "reputation cannot be null");
+ this.reputation = reputation;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets the reputation value for a specific {@link ReputationType}.
+ *
+ * @param type The {@link ReputationType type} of reputation to get.
+ * @return The value of the {@link ReputationType type}.
+ */
+ public int getReputation(final ReputationType type) {
2021-06-11 14:02:28 +02:00
+ Preconditions.checkNotNull(type, "the reputation type cannot be null");
+ return this.reputation.getOrDefault(type, 0);
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Sets the reputation value for a specific {@link ReputationType}.
+ *
+ * @param type The {@link ReputationType type} of reputation to set.
+ * @param value The value of the {@link ReputationType type}.
+ */
+ public void setReputation(final ReputationType type, final int value) {
2021-06-11 14:02:28 +02:00
+ Preconditions.checkNotNull(type, "the reputation type cannot be null");
+ this.reputation.put(type, value);
+ }
+
+ /**
+ * Gets if a reputation value is currently set for a specific {@link ReputationType}.
+ *
+ * @param type The {@link ReputationType type} to check
+ * @return If there is a value for this {@link ReputationType type} set.
+ */
+ public boolean hasReputationSet(final ReputationType type) {
+ return this.reputation.containsKey(type);
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/villager/ReputationType.java b/src/main/java/com/destroystokyo/paper/entity/villager/ReputationType.java
new file mode 100644
index 0000000000000000000000000000000000000000..5600fcdc9795a9f49091db48d73bbd4964b8b737
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/villager/ReputationType.java
@@ -0,0 +1,36 @@
+package com.destroystokyo.paper.entity.villager;
+
+/**
+ * A type of reputation gained with a {@link org.bukkit.entity.Villager Villager}.
+ * <p>
+ * All types but {@link #MAJOR_POSITIVE} are shared to other villagers.
+ */
+public enum ReputationType {
+ /**
+ * A gossip with a majorly negative effect. This is only gained through killing a nearby
+ * villager.
+ */
+ MAJOR_NEGATIVE,
+
+ /**
+ * A gossip with a minor negative effect. This is only gained through damaging a villager.
+ */
+ MINOR_NEGATIVE,
+
+ /**
+ * A gossip with a minor positive effect. This is only gained through curing a zombie
+ * villager.
+ */
+ MINOR_POSITIVE,
+
+ /**
+ * A gossip with a major positive effect. This is only gained through curing a zombie
+ * villager.
+ */
+ MAJOR_POSITIVE,
+
+ /**
+ * A gossip with a minor positive effect. This is only gained through trading with a villager.
+ */
+ TRADING,
+}
diff --git a/src/main/java/org/bukkit/entity/Villager.java b/src/main/java/org/bukkit/entity/Villager.java
Updated Upstream (Bukkit/CraftBukkit) (#11501) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: bb4e97c6 Add support for Java 23 bc6874dd Bump asm to 9.7.1 50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives 758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds 133a64a7 Improve Registry#getOrThrow messages be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields d1b31df2 PR-1062: Clarify BeaconView documentation 3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion 967a7301 SPIGOT-7906: Increase YAML nesting limit to 100 6ecf033d SPIGOT-7899: Smithing recipes don't require inputs CraftBukkit Changes: 0a7bd6c81 PR-1493: Improve reroute performance and add some tests 54941524c Add support for Java 23 f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius ded183674 Fix HIDE_ENCHANTS flag in items without enchantments 308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter 72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives 11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions 45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set 963459791 Increase outdated build delay fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks 2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event 527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty 5529a1769 Implement base methods for tags 30fbdbaaf Improve Registry#getOrThrow messages 6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields 5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null) d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init 98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent f35bae9ec Fix missing hasJukeboxPlayable 8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item 7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
2024-10-21 00:06:54 +02:00
index 5a61175ccfe67c0a3c55cc2b84772fa8f6e6a6cb..98a7c5c549e797100f6aaf440606ef31a2be1e3b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/entity/Villager.java
+++ b/src/main/java/org/bukkit/entity/Villager.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 3a3bea52 SPIGOT-7829: Increase maximum outgoing plugin message size to match Vanilla intention 5cd1c8cb SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT a8e278f0 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 53729d12 Remove spurious ApiStatus.Internal annotation b9f57486 SPIGOT-7799, PR-1039: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 7983b966 PR-1029: Trial changing a small number of inner enums to classes/interfaces to better support custom values CraftBukkit Changes: 403accd56 SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT 812761660 Increase outdated build delay bed1e3ff6 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 2444c8b23 SPIGOT-7823: Suspicious sand and gravel material are not marked as having gravity correctly aceddcd0b SPIGOT-7820: Enum changes - duplicate method name a0d2d6a84 SPIGOT-7813: Material#isInteractable() always returns false 8fd64b091 SPIGOT-7806: Handle both loot and inventory item drop behaviour in PlayerDeathEvent a4ee40b74 SPIGOT-7799, PR-1436: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 082aa51c5 PR-1424: Trial changing a small number of inner enums to classes/interfaces to better support custom values 66e78a96b SPIGOT-7815: Consider EntityDamageEvent status for Wolf armor damage Spigot Changes: 5bbef5ad SPIGOT-7834: Modify max value for generic.max_absorption
2024-07-18 10:13:20 +02:00
@@ -3,6 +3,8 @@ package org.bukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
2021-06-11 14:02:28 +02:00
import java.util.Locale;
+import java.util.Map; // Paper
+import java.util.UUID; // Paper
import org.bukkit.Keyed;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
Updated Upstream (Bukkit/CraftBukkit) (#11501) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: bb4e97c6 Add support for Java 23 bc6874dd Bump asm to 9.7.1 50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives 758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds 133a64a7 Improve Registry#getOrThrow messages be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields d1b31df2 PR-1062: Clarify BeaconView documentation 3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion 967a7301 SPIGOT-7906: Increase YAML nesting limit to 100 6ecf033d SPIGOT-7899: Smithing recipes don't require inputs CraftBukkit Changes: 0a7bd6c81 PR-1493: Improve reroute performance and add some tests 54941524c Add support for Java 23 f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius ded183674 Fix HIDE_ENCHANTS flag in items without enchantments 308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter 72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives 11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions 45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set 963459791 Increase outdated build delay fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks 2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event 527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty 5529a1769 Implement base methods for tags 30fbdbaaf Improve Registry#getOrThrow messages 6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields 5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null) d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init 98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent f35bae9ec Fix missing hasJukeboxPlayable 8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item 7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
2024-10-21 00:06:54 +02:00
@@ -281,4 +283,50 @@ public interface Villager extends AbstractVillager {
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 3a3bea52 SPIGOT-7829: Increase maximum outgoing plugin message size to match Vanilla intention 5cd1c8cb SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT a8e278f0 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 53729d12 Remove spurious ApiStatus.Internal annotation b9f57486 SPIGOT-7799, PR-1039: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 7983b966 PR-1029: Trial changing a small number of inner enums to classes/interfaces to better support custom values CraftBukkit Changes: 403accd56 SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT 812761660 Increase outdated build delay bed1e3ff6 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 2444c8b23 SPIGOT-7823: Suspicious sand and gravel material are not marked as having gravity correctly aceddcd0b SPIGOT-7820: Enum changes - duplicate method name a0d2d6a84 SPIGOT-7813: Material#isInteractable() always returns false 8fd64b091 SPIGOT-7806: Handle both loot and inventory item drop behaviour in PlayerDeathEvent a4ee40b74 SPIGOT-7799, PR-1436: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 082aa51c5 PR-1424: Trial changing a small number of inner enums to classes/interfaces to better support custom values 66e78a96b SPIGOT-7815: Consider EntityDamageEvent status for Wolf armor damage Spigot Changes: 5bbef5ad SPIGOT-7834: Modify max value for generic.max_absorption
2024-07-18 10:13:20 +02:00
return Lists.newArrayList(Registry.VILLAGER_PROFESSION).toArray(new Profession[0]);
2021-06-11 14:02:28 +02:00
}
}
+
+ // Paper start - Add villager reputation API
+ /**
+ * Get the {@link com.destroystokyo.paper.entity.villager.Reputation reputation}
+ * for a specific player by {@link UUID}.
+ *
+ * @param uniqueId The {@link UUID} of the player to get the reputation of.
+ * @return The player's copied reputation with this villager.
+ */
+ @NotNull
2021-06-11 14:02:28 +02:00
+ public com.destroystokyo.paper.entity.villager.Reputation getReputation(@NotNull UUID uniqueId);
+
+ /**
+ * Get all {@link com.destroystokyo.paper.entity.villager.Reputation reputations}
+ * for all players mapped by their {@link UUID unique IDs}.
+ *
+ * @return All {@link com.destroystokyo.paper.entity.villager.Reputation reputations} for all players
+ * in a copied map.
+ */
+ @NotNull
+ public Map<UUID, com.destroystokyo.paper.entity.villager.Reputation> getReputations();
+
+ /**
+ * Set the {@link com.destroystokyo.paper.entity.villager.Reputation reputation}
+ * for a specific player by {@link UUID}.
+ *
+ * @param uniqueId The {@link UUID} of the player to set the reputation of.
+ * @param reputation The {@link com.destroystokyo.paper.entity.villager.Reputation reputation} to set.
+ */
+ public void setReputation(@NotNull UUID uniqueId, @NotNull com.destroystokyo.paper.entity.villager.Reputation reputation);
+
+ /**
+ * Set all {@link com.destroystokyo.paper.entity.villager.Reputation reputations}
+ * for all players mapped by their {@link UUID unique IDs}.
+ *
+ * @param reputations All {@link com.destroystokyo.paper.entity.villager.Reputation reputations}
+ * for all players mapped by their {@link UUID unique IDs}.
+ */
+ public void setReputations(@NotNull Map<UUID, com.destroystokyo.paper.entity.villager.Reputation> reputations);
+
+ /**
+ * Clear all reputations from this villager. This removes every single
+ * reputation regardless of its impact and the player associated.
+ */
+ public void clearReputations();
+ // Paper end
}