use of net.minecraft.server.v1_15_R1.PacketDataSerializer in project Denizen-For-Bukkit by DenizenScript.
the class PacketOutTradeList_v1_10_R1 method setTradeOffers.
@Override
public void setTradeOffers(List<TradeOffer> tradeOffers) {
try {
PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer());
serializer.a("MC|TrList");
serializer.writeInt(container);
serializer.writeByte((byte) (tradeOffers.size() & 255));
for (TradeOffer tradeOffer : tradeOffers) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getFirstCost()));
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getProduct()));
boolean hasSecondCost = tradeOffer.hasSecondCost();
serializer.writeBoolean(hasSecondCost);
if (hasSecondCost) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getSecondCost()));
}
serializer.writeBoolean(tradeOffer.isUsedMaxTimes());
serializer.writeInt(tradeOffer.getCurrentUses());
serializer.writeInt(tradeOffer.getMaxUses());
}
internal.a(serializer);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_15_R1.PacketDataSerializer in project solinia3-core by mixxit.
the class ForgeUtils method sendForgeMessage.
public static void sendForgeMessage(Player player, String channelName, byte discriminator, String message) throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(stream);
try {
// diesieben07 - Forge uses an unsigned byte for the discriminator, for a start
// dataOut.writeInt(discriminator);
dataOut.writeByte(discriminator);
// diesieben07 - But you should really send some kind of length prefix
// and then only read that much of the string
// You're already using DataOuput, it has writeUTFString
// dataOut.write(message.getBytes(StandardCharsets.UTF_8));
dataOut.writeUTF(message);
PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload(new MinecraftKey(channelName), new PacketDataSerializer(Unpooled.wrappedBuffer(stream.toByteArray())));
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
} finally {
dataOut.close();
stream.close();
}
}
use of net.minecraft.server.v1_15_R1.PacketDataSerializer in project Denizen-For-Bukkit by DenizenScript.
the class PacketOutTradeList_v1_11_R1 method setTradeOffers.
@Override
public void setTradeOffers(List<TradeOffer> tradeOffers) {
try {
PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer());
serializer.a("MC|TrList");
serializer.writeInt(container);
serializer.writeByte((byte) (tradeOffers.size() & 255));
for (TradeOffer tradeOffer : tradeOffers) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getFirstCost()));
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getProduct()));
boolean hasSecondCost = tradeOffer.hasSecondCost();
serializer.writeBoolean(hasSecondCost);
if (hasSecondCost) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getSecondCost()));
}
serializer.writeBoolean(tradeOffer.isUsedMaxTimes());
serializer.writeInt(tradeOffer.getCurrentUses());
serializer.writeInt(tradeOffer.getMaxUses());
}
internal.a(serializer);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_15_R1.PacketDataSerializer in project Denizen-For-Bukkit by DenizenScript.
the class PacketOutTradeList_v1_8_R3 method setTradeOffers.
@Override
public void setTradeOffers(List<TradeOffer> tradeOffers) {
try {
PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer());
serializer.a("MC|TrList");
serializer.writeInt(container);
serializer.writeByte((byte) (tradeOffers.size() & 255));
for (TradeOffer tradeOffer : tradeOffers) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getFirstCost()));
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getProduct()));
boolean hasSecondCost = tradeOffer.hasSecondCost();
serializer.writeBoolean(hasSecondCost);
if (hasSecondCost) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getSecondCost()));
}
serializer.writeBoolean(tradeOffer.isUsedMaxTimes());
serializer.writeInt(tradeOffer.getCurrentUses());
serializer.writeInt(tradeOffer.getMaxUses());
}
internal.a(serializer);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_15_R1.PacketDataSerializer in project Denizen-For-Bukkit by DenizenScript.
the class PacketOutTradeList_v1_9_R2 method setTradeOffers.
@Override
public void setTradeOffers(List<TradeOffer> tradeOffers) {
try {
PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer());
serializer.a("MC|TrList");
serializer.writeInt(container);
serializer.writeByte((byte) (tradeOffers.size() & 255));
for (TradeOffer tradeOffer : tradeOffers) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getFirstCost()));
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getProduct()));
boolean hasSecondCost = tradeOffer.hasSecondCost();
serializer.writeBoolean(hasSecondCost);
if (hasSecondCost) {
serializer.a(CraftItemStack.asNMSCopy(tradeOffer.getSecondCost()));
}
serializer.writeBoolean(tradeOffer.isUsedMaxTimes());
serializer.writeInt(tradeOffer.getCurrentUses());
serializer.writeInt(tradeOffer.getMaxUses());
}
internal.a(serializer);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations