Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/net/aufdemrand/denizen/utilities/packets/OpenBook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.aufdemrand.denizen.utilities.packets; | ||
|
||
import io.netty.buffer.Unpooled; | ||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
import net.minecraft.server.v1_8_R1.PacketDataSerializer; | ||
import net.minecraft.server.v1_8_R1.PacketPlayOutCustomPayload; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
public class OpenBook { | ||
|
||
private static final Field channel, packet_data; | ||
|
||
static { | ||
Map<String, Field> fields = PacketHelper.registerFields(PacketPlayOutCustomPayload.class); | ||
channel = fields.get("a"); | ||
packet_data = fields.get("b"); | ||
} | ||
|
||
public static PacketPlayOutCustomPayload getOpenBookPacket() { | ||
PacketPlayOutCustomPayload customPayloadPacket = new PacketPlayOutCustomPayload(); | ||
try { | ||
channel.set(customPayloadPacket, "MC|BOpen"); | ||
packet_data.set(customPayloadPacket, new PacketDataSerializer(Unpooled.buffer())); | ||
} catch (Exception e) { | ||
dB.echoError(e); | ||
} | ||
return customPayloadPacket; | ||
} | ||
|
||
public static void openBook(Player player) { | ||
PacketPlayOutCustomPayload customPayloadPacket = getOpenBookPacket(); | ||
PacketHelper.sendPacket(player, customPayloadPacket); | ||
} | ||
|
||
} |