Skip to content

Commit

Permalink
Villager expression updates (#7352)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneBeee authored Jan 1, 2025
1 parent bc9666e commit 9c6cae0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.entity.ZombieVillager;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Villager Profession")
@Description("Represents the profession of a villager.")
@Description("Represents the profession of a villager/zombie villager.")
@Examples({
"set {_p} to villager profession of event-entity",
"villager profession of event-entity = nitwit profession",
Expand All @@ -32,6 +33,8 @@ public class ExprVillagerProfession extends SimplePropertyExpression<LivingEntit
public @Nullable Profession convert(LivingEntity from) {
if (from instanceof Villager villager)
return villager.getProfession();
else if (from instanceof ZombieVillager zombie)
return zombie.getVillagerProfession();
return null;
}

Expand All @@ -50,6 +53,8 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
for (LivingEntity livingEntity : getExpr().getArray(event)) {
if (livingEntity instanceof Villager villager)
villager.setProfession(profession);
else if (livingEntity instanceof ZombieVillager zombie)
zombie.setVillagerProfession(profession);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Type;
import org.bukkit.entity.ZombieVillager;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Villager Type")
@Description("Represents the type of a villager. This usually represents the biome the villager is from.")
@Description("Represents the type of a villager/zombie villager. This usually represents the biome the villager is from.")
@Examples({
"set {_type} to villager type of {_villager}",
"villager type of {_villager} = plains",
Expand All @@ -31,6 +32,8 @@ public class ExprVillagerType extends SimplePropertyExpression<LivingEntity, Typ
public @Nullable Type convert(LivingEntity from) {
if (from instanceof Villager villager)
return villager.getVillagerType();
else if (from instanceof ZombieVillager zombie)
return zombie.getVillagerType();
return null;
}

Expand All @@ -50,6 +53,8 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
for (LivingEntity livingEntity : getExpr().getArray(event)) {
if (livingEntity instanceof Villager villager)
villager.setVillagerType(type);
else if (livingEntity instanceof ZombieVillager zombie)
zombie.setVillagerType(type);
}
}

Expand Down

0 comments on commit 9c6cae0

Please sign in to comment.