Skip to content

Commit

Permalink
Adjust dPlayer.open_book, add dPlayer.open_offhand_book
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Apr 7, 2016
1 parent 76ba784 commit 6d23cc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -2763,7 +2763,20 @@ else if (split.length > 1) {
// without the player closing the book.
// -->
if (mechanism.matches("open_book")) {
OpenBook.openBook(getPlayerEntity());
OpenBook.openBook(getPlayerEntity(), false);
}

// <--[mechanism]
// @object dPlayer
// @name open_offhand_book
// @input None
// @description
// Forces the player to open the written book in their offhand.
// The book can safely be removed from the player's offhand
// without the player closing the book.
// -->
if (mechanism.matches("open_offhand_book")) {
OpenBook.openBook(getPlayerEntity(), true);
}

// <--[mechanism]
Expand Down
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.server.v1_9_R1.EnumHand;
import net.minecraft.server.v1_9_R1.PacketDataSerializer;
import net.minecraft.server.v1_9_R1.PacketPlayOutCustomPayload;
import org.bukkit.Material;
import org.bukkit.entity.Player;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -35,8 +34,7 @@ public static PacketPlayOutCustomPayload getOpenBookPacket(boolean offHand) {
return customPayloadPacket;
}

public static void openBook(Player player) {
boolean offHand = player.getInventory().getItemInMainHand().getData().getItemType() != Material.WRITTEN_BOOK;
public static void openBook(Player player, boolean offHand) {
PacketPlayOutCustomPayload customPayloadPacket = getOpenBookPacket(offHand);
PacketHelper.sendPacket(player, customPayloadPacket);
}
Expand Down

0 comments on commit 6d23cc5

Please sign in to comment.