net.wesjd.anvilgui.version.impl.Wrapper1_8_R3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spigot-anvil-gui Show documentation
Show all versions of spigot-anvil-gui Show documentation
Upperlevel's fork of WesJD/AnvilGui.
package net.wesjd.anvilgui.version.impl;
import net.wesjd.anvilgui.version.VersionWrapper;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
/**
* {@link VersionWrapper} implemented for NMS version 1_8_R3
* @author Wesley Smith
* @since 1.0
*/
public class Wrapper1_8_R3 implements VersionWrapper {
/**
* {@inheritDoc}
*/
@Override
public int getNextContainerId(Player player) {
return toNMS(player).nextContainerCounter();
}
/**
* {@inheritDoc}
*/
@Override
public void handleInventoryCloseEvent(Player player) {
CraftEventFactory.handleInventoryCloseEvent(toNMS(player));
}
/**
* {@inheritDoc}
*/
@Override
public void sendPacketOpenWindow(Player player, int containerId) {
toNMS(player).playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, "minecraft:anvil", new ChatMessage(Blocks.ANVIL.a() + ".name")));
}
/**
* {@inheritDoc}
*/
@Override
public void sendPacketCloseWindow(Player player, int containerId) {
toNMS(player).playerConnection.sendPacket(new PacketPlayOutCloseWindow(containerId));
}
/**
* {@inheritDoc}
*/
@Override
public void setActiveContainerDefault(Player player) {
toNMS(player).activeContainer = toNMS(player).defaultContainer;
}
/**
* {@inheritDoc}
*/
@Override
public void setActiveContainer(Player player, Object container) {
toNMS(player).activeContainer = (Container) container;
}
/**
* {@inheritDoc}
*/
@Override
public void setActiveContainerId(Object container, int containerId) {
((Container) container).windowId = containerId;
}
/**
* {@inheritDoc}
*/
@Override
public void addActiveContainerSlotListener(Object container, Player player) {
((Container) container).addSlotListener(toNMS(player));
}
/**
* {@inheritDoc}
*/
@Override
public Inventory toBukkitInventory(Object container) {
return ((Container) container).getBukkitView().getTopInventory();
}
/**
* {@inheritDoc}
*/
@Override
public Object newContainerAnvil(Player player) {
return new AnvilContainer(toNMS(player));
}
/**
* Turns a {@link Player} into an NMS one
* @param player The player to be converted
* @return the NMS EntityPlayer
*/
private EntityPlayer toNMS(Player player) {
return ((CraftPlayer) player).getHandle();
}
/**
* Modifications to ContainerAnvil that makes it so you don't have to have xp to use this anvil
*/
private class AnvilContainer extends ContainerAnvil {
public AnvilContainer(EntityHuman entityhuman) {
super(entityhuman.inventory, entityhuman.world, new BlockPosition(0, 0, 0), entityhuman);
}
@Override
public boolean a(EntityHuman human) {
return true;
}
}
}