use of com.comphenix.protocol.wrappers.nbt.NbtCompound in project RedProtect by FabioZumbi12.
the class RPProtocolLib method removeAttributes.
public static ItemStack removeAttributes(ItemStack item) {
if (!MinecraftReflection.isCraftItemStack(item)) {
item = MinecraftReflection.getBukkitItemStack(item);
}
NbtCompound compound = (NbtCompound) NbtFactory.fromItemTag(item);
compound.put(NbtFactory.ofList("AttributeModifiers"));
return item;
}
use of com.comphenix.protocol.wrappers.nbt.NbtCompound in project VoxelGamesLibv2 by VoxelGamesLib.
the class SignPlaceholders method init.
public void init() {
registerPlaceholders();
Bukkit.getWorlds().stream().flatMap(w -> Arrays.stream(w.getLoadedChunks())).flatMap(s -> Arrays.stream(s.getTileEntities())).filter(s -> s instanceof Sign).map(s -> (Sign) s).forEach(s -> lastSeenSigns.put(s.getLocation(), s));
// modify update packets
protocolManager.addPacketListener(new PacketAdapter(voxelGamesLib, PacketType.Play.Server.TILE_ENTITY_DATA) {
@Override
public void onPacketSending(@Nonnull PacketEvent event) {
int action = event.getPacket().getIntegers().read(0);
// 9 = set sign text action
if (action != 9) {
return;
}
NbtCompound data = (NbtCompound) event.getPacket().getNbtModifier().read(0);
// read data
Component[] lines = new Component[4];
String[] rawLines = new String[4];
for (int i = 0; i < lines.length; i++) {
lines[i] = ComponentSerializers.JSON.deserialize(data.getString("Text" + (i + 1)));
rawLines[i] = ChatUtil.toPlainText(lines[i]);
}
// sometimes its a double, sometimes its an int...
double x;
double y;
double z;
try {
x = data.getDouble("x");
y = data.getDouble("y");
z = data.getDouble("z");
} catch (ClassCastException ex) {
x = data.getInteger("x");
y = data.getInteger("y");
z = data.getInteger("z");
}
Location loc = new Location(event.getPlayer().getWorld(), x, y, z);
if (event.getPlayer().getLocation().distanceSquared(loc) > 200 * 200) {
return;
}
Block b = loc.getBlock();
if (!(b.getState() instanceof Sign)) {
return;
}
Sign sign = (Sign) b.getState();
lastSeenSigns.put(loc, sign);
Optional<User> user = userHandler.getUser(event.getPlayer().getUniqueId());
if (!user.isPresent()) {
return;
}
// call sign placeholders
modifySign(user.get(), loc, rawLines, lines);
// modify packet
for (int i = 0; i < lines.length; i++) {
data.put("Text" + (i + 1), ComponentSerializers.JSON.serialize(lines[i]));
}
}
});
// update task
new BukkitRunnable() {
@Override
public void run() {
lastSeenSigns.forEach((loc, sign) -> sign.update());
}
}.runTaskTimer(voxelGamesLib, 20, 20);
}
Aggregations