3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 02:50:09 +01:00
Paper/patches/api/0188-Add-villager-reputation-API.patch
Nassim Jahnke dd11ef8441
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

176 Zeilen
6.6 KiB
Diff

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..0a69e21b0b3001c9cc50951b4b8bd593f6fa74be
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/villager/Reputation.java
@@ -0,0 +1,57 @@
+package com.destroystokyo.paper.entity.villager;
+
+import com.google.common.base.Preconditions;
+
+import java.util.EnumMap;
+import java.util.Map;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * A reputation score for a player on a villager.
+ */
+public final class Reputation {
+
+ @NotNull
+ private final Map<ReputationType, Integer> reputation;
+
+ public Reputation() {
+ this(new EnumMap<>(ReputationType.class));
+ }
+
+ public Reputation(@NotNull Map<ReputationType, Integer> reputation) {
+ Preconditions.checkNotNull(reputation, "reputation cannot be null");
+ this.reputation = reputation;
+ }
+
+ /**
+ * 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(@NotNull ReputationType type) {
+ Preconditions.checkNotNull(type, "the reputation type cannot be null");
+ return this.reputation.getOrDefault(type, 0);
+ }
+
+ /**
+ * 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(@NotNull ReputationType type, int value) {
+ 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(@NotNull ReputationType type) {
+ return this.reputation.containsKey(type);
+ }
+}
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
index ecb0f32a4449f8000248c4bebf89a56df186899f..d839630d7b2e51629e52edf24e7c6dd86b5f58f6 100644
--- a/src/main/java/org/bukkit/entity/Villager.java
+++ b/src/main/java/org/bukkit/entity/Villager.java
@@ -3,6 +3,8 @@ package org.bukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
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;
@@ -289,4 +291,50 @@ public interface Villager extends AbstractVillager {
return Lists.newArrayList(Registry.VILLAGER_PROFESSION).toArray(new Profession[0]);
}
}
+
+ // 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
+ 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
}