net.wesjd.anvilgui.version.impl.Wrapper1_9_R2 Maven / Gradle / Ivy
package net.wesjd.anvilgui.version.impl;
import net.wesjd.anvilgui.version.VersionWrapper;
import net.minecraft.server.v1_9_R2.*;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_9_R2.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
/**
* {@link VersionWrapper} implemented for NMS version 1_9_R2
* @author Wesley Smith
* @since 1.0
*/
public class Wrapper1_9_R2 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 entityhuman) {
return true;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy