Fixed itemstack/equipment error

Fixed packet events error
Added blacklist api methods
This commit is contained in:
AlexDev_ 2024-02-13 22:48:34 +01:00
parent abfdc1901b
commit 475c49c7e2
6 changed files with 56 additions and 5 deletions

@ -100,6 +100,28 @@ public interface Npc extends PropertyHolder {
*/ */
void respawn(Player player); void respawn(Player player);
/**
* Blacklists a player from sending packets for this NPC
* This means that the run task won't send packets to the player
*
* @param player The player to be blacklisted
*/
void blacklist(Player player);
/**
* Removes a player from the blacklist, allowing packets to be sent to them for this NPC.
*
* @param player The player to be removed from the blacklist
*/
void unblacklist(Player player);
/**
* Gets if a player is blacklisted from sending packets for this NPC
* @param player The player to check
* @return If the player is blacklisted
*/
boolean isBlacklisted(Player player);
/** /**
* Sets the head rotation of this NPC for a player * Sets the head rotation of this NPC for a player
* @param player The {@link Player} to set the head rotation for * @param player The {@link Player} to set the head rotation for

@ -20,7 +20,7 @@ dependencies {
compileOnly "com.google.code.gson:gson:2.10.1" // JSON parsing compileOnly "com.google.code.gson:gson:2.10.1" // JSON parsing
compileOnly "org.bstats:bstats-bukkit:3.0.2" // Plugin stats compileOnly "org.bstats:bstats-bukkit:3.0.2" // Plugin stats
compileOnly "me.robertlit:SpigotResourcesAPI:2.0" // Spigot API wrapper for update checker compileOnly "me.robertlit:SpigotResourcesAPI:2.0" // Spigot API wrapper for update checker
compileOnly "com.github.retrooper.packetevents:spigot:2.1.0" // Packets compileOnly "com.github.retrooper.packetevents:spigot:2.2.0" // Packets
compileOnly "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1" // Configs compileOnly "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1" // Configs
compileOnly "lol.pyr:director-adventure:2.1.1" // Commands compileOnly "lol.pyr:director-adventure:2.1.1" // Commands

@ -54,8 +54,8 @@ public class ZNpcsPlusBootstrap extends JavaPlugin {
loader.loadLibrary("me.robertlit", "SpigotResourcesAPI", "2.0", "https://repo.pyr.lol/releases"); loader.loadLibrary("me.robertlit", "SpigotResourcesAPI", "2.0", "https://repo.pyr.lol/releases");
loader.loadLibrary(decrypt("com..github..retrooper..packetevents"), "api", "2.1.0", "https://repo.codemc.io/repository/maven-releases/"); loader.loadLibrary(decrypt("com..github..retrooper..packetevents"), "api", "2.2.0", "https://repo.codemc.io/repository/maven-releases/");
loader.loadLibrary(decrypt("com..github..retrooper..packetevents"), "spigot", "2.1.0", "https://repo.codemc.io/repository/maven-releases/"); loader.loadLibrary(decrypt("com..github..retrooper..packetevents"), "spigot", "2.2.0", "https://repo.codemc.io/repository/maven-releases/");
loader.loadLibrary(decrypt("space..arim..dazzleconf"), "dazzleconf-core", "1.2.1"); loader.loadLibrary(decrypt("space..arim..dazzleconf"), "dazzleconf-core", "1.2.1");
loader.loadLibrary(decrypt("space..arim..dazzleconf"), "dazzleconf-ext-snakeyaml", "1.2.1"); loader.loadLibrary(decrypt("space..arim..dazzleconf"), "dazzleconf-ext-snakeyaml", "1.2.1");

@ -1,6 +1,7 @@
package lol.pyr.znpcsplus.npc; package lol.pyr.znpcsplus.npc;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.npc.Npc; import lol.pyr.znpcsplus.api.npc.Npc;
import lol.pyr.znpcsplus.api.npc.NpcType; import lol.pyr.znpcsplus.api.npc.NpcType;
@ -18,6 +19,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -148,13 +150,19 @@ public class NpcImpl extends Viewable implements Npc {
@Override @Override
public <T> void setProperty(EntityProperty<T> key, T value) { public <T> void setProperty(EntityProperty<T> key, T value) {
setProperty((EntityPropertyImpl<T>) key, value ); setProperty((EntityPropertyImpl<T>) key, value);
} }
public <T> void setProperty(EntityPropertyImpl<T> key, T value) { public <T> void setProperty(EntityPropertyImpl<T> key, T value) {
if (key == null) return; if (key == null) return;
if (value == null || value.equals(key.getDefaultValue())) propertyMap.remove(key); if (value == null || value.equals(key.getDefaultValue())) propertyMap.remove(key);
else propertyMap.put(key, value); if (value instanceof ItemStack) {
ItemStack item = (ItemStack) value;
com.github.retrooper.packetevents.protocol.item.ItemStack packetItem = SpigotConversionUtil.fromBukkitItemStack(item);
propertyMap.put(key, packetItem);
} else {
propertyMap.put(key, value);
}
UNSAFE_refreshProperty(key); UNSAFE_refreshProperty(key);
} }

@ -47,6 +47,11 @@ public class NpcProcessorTask extends BukkitRunnable {
if (npc.isVisibleTo(player)) npc.hide(player); if (npc.isVisibleTo(player)) npc.hide(player);
continue; continue;
} }
if (npc.isBlacklisted(player)) {
continue;
}
double distance = player.getLocation().distanceSquared(npc.getBukkitLocation()); double distance = player.getLocation().distanceSquared(npc.getBukkitLocation());
// visibility // visibility

@ -22,6 +22,7 @@ public abstract class Viewable {
} }
private final Set<Player> viewers = ConcurrentHashMap.newKeySet(); private final Set<Player> viewers = ConcurrentHashMap.newKeySet();
private final Set<Player> blacklisted = ConcurrentHashMap.newKeySet();
public Viewable() { public Viewable() {
all.add(new WeakReference<>(this)); all.add(new WeakReference<>(this));
@ -30,6 +31,7 @@ public abstract class Viewable {
public void delete() { public void delete() {
UNSAFE_hideAll(); UNSAFE_hideAll();
viewers.clear(); viewers.clear();
blacklisted.clear();
} }
public void respawn() { public void respawn() {
@ -55,8 +57,22 @@ public abstract class Viewable {
UNSAFE_hide(player); UNSAFE_hide(player);
} }
public void blacklist(Player player) {
blacklisted.add(player);
hide(player);
}
public void unblacklist(Player player) {
blacklisted.remove(player);
}
public boolean isBlacklisted(Player player) {
return blacklisted.contains(player);
}
public void UNSAFE_removeViewer(Player player) { public void UNSAFE_removeViewer(Player player) {
viewers.remove(player); viewers.remove(player);
blacklisted.remove(player);
} }
protected void UNSAFE_hideAll() { protected void UNSAFE_hideAll() {