Add villager reputation API

This commit is contained in:
Mariell Hoversholm
2020-04-22 23:13:49 +02:00
parent ef291e36d1
commit 3dc7ae31ea
3 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
package com.destroystokyo.paper.entity.villager;
import com.google.common.base.Preconditions;
import java.util.EnumMap;
import java.util.Map;
import org.jspecify.annotations.NullMarked;
/**
* A reputation score for a player on a villager.
*/
@NullMarked
public final class Reputation {
private final Map<ReputationType, Integer> reputation;
public Reputation() {
this(new EnumMap<>(ReputationType.class));
}
public Reputation(final 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(final 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(final ReputationType type, final 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(final ReputationType type) {
return this.reputation.containsKey(type);
}
}

View File

@@ -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,
}