mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 01:27:33 +01:00
Fix playeranimation on outdated minecraft versions
This commit is contained in:
parent
7a229def7d
commit
ad0f5caac5
@ -3,6 +3,7 @@ package net.citizensnpcs.util;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -50,20 +51,30 @@ public enum PlayerAnimation {
|
||||
}
|
||||
|
||||
public void play(Player from, int radius) {
|
||||
Location loc = from.getLocation();
|
||||
Location cloc = new Location(null, 0, 0, 0);
|
||||
List<Player> to = Lists.newArrayList();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(loc, radius)) {
|
||||
if (loc.getWorld() != player.getWorld() || !player.canSee(from)
|
||||
|| loc.distance(player.getLocation(cloc)) > radius) {
|
||||
continue;
|
||||
play(from, () -> {
|
||||
Location loc = from.getLocation();
|
||||
Location cloc = new Location(null, 0, 0, 0);
|
||||
List<Player> to = Lists.newArrayList();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(loc, radius)) {
|
||||
if (loc.getWorld() != player.getWorld() || !player.canSee(from)
|
||||
|| loc.distance(player.getLocation(cloc)) > radius) {
|
||||
continue;
|
||||
}
|
||||
to.add(player);
|
||||
}
|
||||
to.add(player);
|
||||
}
|
||||
play(from, to);
|
||||
return to;
|
||||
});
|
||||
}
|
||||
|
||||
public void play(Player player, Iterable<Player> to) {
|
||||
play(player, () -> to);
|
||||
}
|
||||
|
||||
public void play(Player player, Player to) {
|
||||
play(player, () -> ImmutableList.of(to));
|
||||
}
|
||||
|
||||
public void play(Player player, Supplier<Iterable<Player>> to) {
|
||||
if (this == SIT) {
|
||||
if (player instanceof NPCHolder) {
|
||||
((NPCHolder) player).getNPC().getOrAddTrait(SitTrait.class).setSitting(player.getLocation());
|
||||
@ -120,7 +131,7 @@ public enum PlayerAnimation {
|
||||
}
|
||||
return;
|
||||
} else if (this == STOP_USE_ITEM || this == START_USE_MAINHAND_ITEM || this == START_USE_OFFHAND_ITEM) {
|
||||
NMS.playAnimation(this, player, to);
|
||||
NMS.playAnimation(this, player, to.get());
|
||||
if (player.hasMetadata("citizens-using-item-id")) {
|
||||
Bukkit.getScheduler().cancelTask(player.getMetadata("citizens-using-item-id").get(0).asInt());
|
||||
player.removeMetadata("citizens-using-item-id", CitizensAPI.getPlugin());
|
||||
@ -140,8 +151,8 @@ public enum PlayerAnimation {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, to);
|
||||
NMS.playAnimation(PlayerAnimation.this, player, to);
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, to.get());
|
||||
NMS.playAnimation(PlayerAnimation.this, player, to.get());
|
||||
if (!player.hasMetadata("citizens-using-item-id")) {
|
||||
player.setMetadata("citizens-using-item-id",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId()));
|
||||
@ -152,17 +163,13 @@ public enum PlayerAnimation {
|
||||
}
|
||||
return;
|
||||
}
|
||||
NMS.playAnimation(this, player, to);
|
||||
}
|
||||
|
||||
public void play(Player player, Player to) {
|
||||
play(player, ImmutableList.of(to));
|
||||
NMS.playAnimation(this, player, to.get());
|
||||
}
|
||||
|
||||
private static final Set<Material> BAD_ITEMS_TO_USE = EnumSet.noneOf(Material.class);
|
||||
static {
|
||||
try {
|
||||
BAD_ITEMS_TO_USE.add(Material.SPYGLASS);
|
||||
BAD_ITEMS_TO_USE.add(Material.valueOf("SPYGLASS"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user