Skip to content

Commit

Permalink
Support FollowTrait on 1.8.8
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 2, 2023
1 parent a1e4255 commit 49036e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main/src/main/java/net/citizensnpcs/trait/FollowTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.util.Util;

/**
* Persists a {@link Player} to follow while spawned. Optionally allows protecting of the player as well.
Expand Down Expand Up @@ -98,7 +99,7 @@ public void run() {
return;
entity = Bukkit.getPlayer(followingUUID);
if (entity == null) {
entity = Bukkit.getEntity(followingUUID);
entity = Util.getEntity(followingUUID);
}
if (entity == null)
return;
Expand Down
19 changes: 19 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -218,6 +219,23 @@ public static Scoreboard getDummyScoreboard() {
return DUMMY_SCOREBOARD;
}

public static Entity getEntity(UUID uuid) {
if (SUPPORTS_BUKKIT_GETENTITY) {
try {
return Bukkit.getEntity(uuid);
} catch (Throwable t) {
SUPPORTS_BUKKIT_GETENTITY = false;
}
}
for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) {
if (entity.getUniqueId().equals(uuid))
return entity;
}
}
return null;
}

public static Location getEyeLocation(Entity entity) {
return entity instanceof LivingEntity ? ((LivingEntity) entity).getEyeLocation() : entity.getLocation();
}
Expand Down Expand Up @@ -579,6 +597,7 @@ public static int toTicks(Duration delay) {
}

private static final Scoreboard DUMMY_SCOREBOARD = Bukkit.getScoreboardManager().getNewScoreboard();
private static boolean SUPPORTS_BUKKIT_GETENTITY = true;
private static final DecimalFormat TWO_DIGIT_DECIMAL = new DecimalFormat();

static {
Expand Down

0 comments on commit 49036e1

Please sign in to comment.