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.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -50,20 +51,30 @@ public enum PlayerAnimation {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void play(Player from, int radius) {
|
public void play(Player from, int radius) {
|
||||||
Location loc = from.getLocation();
|
play(from, () -> {
|
||||||
Location cloc = new Location(null, 0, 0, 0);
|
Location loc = from.getLocation();
|
||||||
List<Player> to = Lists.newArrayList();
|
Location cloc = new Location(null, 0, 0, 0);
|
||||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(loc, radius)) {
|
List<Player> to = Lists.newArrayList();
|
||||||
if (loc.getWorld() != player.getWorld() || !player.canSee(from)
|
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(loc, radius)) {
|
||||||
|| loc.distance(player.getLocation(cloc)) > radius) {
|
if (loc.getWorld() != player.getWorld() || !player.canSee(from)
|
||||||
continue;
|
|| loc.distance(player.getLocation(cloc)) > radius) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
to.add(player);
|
||||||
}
|
}
|
||||||
to.add(player);
|
return to;
|
||||||
}
|
});
|
||||||
play(from, to);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void play(Player player, Iterable<Player> 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 (this == SIT) {
|
||||||
if (player instanceof NPCHolder) {
|
if (player instanceof NPCHolder) {
|
||||||
((NPCHolder) player).getNPC().getOrAddTrait(SitTrait.class).setSitting(player.getLocation());
|
((NPCHolder) player).getNPC().getOrAddTrait(SitTrait.class).setSitting(player.getLocation());
|
||||||
|
@ -120,7 +131,7 @@ public enum PlayerAnimation {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (this == STOP_USE_ITEM || this == START_USE_MAINHAND_ITEM || this == START_USE_OFFHAND_ITEM) {
|
} 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")) {
|
if (player.hasMetadata("citizens-using-item-id")) {
|
||||||
Bukkit.getScheduler().cancelTask(player.getMetadata("citizens-using-item-id").get(0).asInt());
|
Bukkit.getScheduler().cancelTask(player.getMetadata("citizens-using-item-id").get(0).asInt());
|
||||||
player.removeMetadata("citizens-using-item-id", CitizensAPI.getPlugin());
|
player.removeMetadata("citizens-using-item-id", CitizensAPI.getPlugin());
|
||||||
|
@ -140,8 +151,8 @@ public enum PlayerAnimation {
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, to);
|
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, to.get());
|
||||||
NMS.playAnimation(PlayerAnimation.this, player, to);
|
NMS.playAnimation(PlayerAnimation.this, player, to.get());
|
||||||
if (!player.hasMetadata("citizens-using-item-id")) {
|
if (!player.hasMetadata("citizens-using-item-id")) {
|
||||||
player.setMetadata("citizens-using-item-id",
|
player.setMetadata("citizens-using-item-id",
|
||||||
new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId()));
|
new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId()));
|
||||||
|
@ -152,17 +163,13 @@ public enum PlayerAnimation {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NMS.playAnimation(this, player, to);
|
NMS.playAnimation(this, player, to.get());
|
||||||
}
|
|
||||||
|
|
||||||
public void play(Player player, Player to) {
|
|
||||||
play(player, ImmutableList.of(to));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<Material> BAD_ITEMS_TO_USE = EnumSet.noneOf(Material.class);
|
private static final Set<Material> BAD_ITEMS_TO_USE = EnumSet.noneOf(Material.class);
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
BAD_ITEMS_TO_USE.add(Material.SPYGLASS);
|
BAD_ITEMS_TO_USE.add(Material.valueOf("SPYGLASS"));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue