本文整理汇总了Java中org.spongepowered.api.item.inventory.type.CarriedInventory类的典型用法代码示例。如果您正苦于以下问题:Java CarriedInventory类的具体用法?Java CarriedInventory怎么用?Java CarriedInventory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CarriedInventory类属于org.spongepowered.api.item.inventory.type包,在下文中一共展示了CarriedInventory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLockOfInventory
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
/**
* Returns the lock for given inventory it exists
*
* @param inventory
* @return the lock for given inventory
*/
public Lock getLockOfInventory(CarriedInventory<?> inventory)
{
Carrier holder = inventory.getCarrier().orElse(null);
if (holder instanceof Entity)
{
return this.getLockForEntityUID(((Entity)holder).getUniqueId());
}
if (holder instanceof MultiBlockCarrier)
{
return getValidLock(((MultiBlockCarrier)holder).getLocation(), null);
}
if (holder instanceof BlockCarrier)
{
return getValidLock(((BlockCarrier)holder).getLocation(), null);
}
return null;
}
示例2: onInventoryOpen
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener
public void onInventoryOpen(InteractInventoryEvent.Open event, @First Player player)
{
if (!(event.getTargetInventory() instanceof CarriedInventory)
|| !((CarriedInventory) event.getTargetInventory()).getCarrier().isPresent())
{
return;
}
Object carrier = ((CarriedInventory) event.getTargetInventory()).getCarrier().get();
Location<World> loc = null;
if (carrier instanceof BlockCarrier)
{
loc = ((BlockCarrier) carrier).getLocation();
}
else if (carrier instanceof Entity)
{
loc = ((Entity) carrier).getLocation();
}
Lock lock = this.manager.getLockOfInventory(((CarriedInventory) event.getTargetInventory()));
if (lock == null) return;
lock.handleInventoryOpen(event, event.getTargetInventory(), loc, player);
}
示例3: onInteract
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener
@Exclude({ClickInventoryEvent.Close.class, ClickInventoryEvent.Open.class})
public void onInteract(ClickInventoryEvent event, @Root Player p) {
try {
//Get target inventory owner
Inventory inv = event.getTargetInventory();
if (!(inv instanceof CarriedInventory)) return;
CarriedInventory cinv = (CarriedInventory) inv;
if (!cinv.getCarrier().isPresent() || !(cinv.getCarrier().get() instanceof User)) return;
User t = (User) cinv.getCarrier().get();
//Check if player is in invsee & Cancel event if player doesn't have permission
UltimateUser up = UltimateCore.get().getUserService().getUser(p);
if (up.get(InventoryKeys.INVSEE_TARGET).isPresent() && up.get(InventoryKeys.INVSEE_TARGET).get().equals(t.getUniqueId())) {
if (!p.hasPermission("uc.inventory.invsee.modify")) {
event.getCursorTransaction().setValid(false);
event.setCancelled(true);
}
}
} catch (Exception ignore) {
}
}
示例4: toString
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
public String toString(boolean unks) {
if (remAs != null) {
return "shared/" + remAs;
}
if (internal instanceof MainPlayerInventory) {
return "player/" + ((PlayerInventory) (internal).parent()).getCarrier().get().getUniqueId().toString();
}
else if (internal instanceof CarriedInventory) {
Object o = ((CarriedInventory) internal).getCarrier().orElse(null);
if (o == null) {
return "((UNKNOWN INVENTORY TYPE))";
}
if (o instanceof Entity) {
return "entity/" + ((Entity) o).getUniqueId().toString();
}
else if (o instanceof TileEntityCarrier) {
LocatableBlock lb = ((TileEntityCarrier) o).getLocatableBlock();
return "block/" + new LocationTag(new UtilLocation(lb.getPosition(), lb.getWorld()));
}
}
if (!unks) {
// TODO: Handle all inventory types somehow???
throw new RuntimeException("Inventory type not known to the system!");
}
else {
return "((UNKNOWN INVENTORY TYPE))";
}
}
示例5: onChangeInventory
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener(order = Order.POST)
public void onChangeInventory(ChangeInventoryEvent event) {
if (event.getTargetInventory() instanceof CarriedInventory<?>) {
Optional<?> carrier = ((CarriedInventory) event.getTargetInventory()).getCarrier();
if (carrier.isPresent() && carrier.get() instanceof TileEntityCarrier) {
checkBlockChange(((TileEntityCarrier) carrier.get()).getLocation().createSnapshot());
}
}
}
示例6: onChangeInventory
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Listener
public void onChangeInventory(ChangeInventoryEvent event, @First Player player,
@Getter("getTargetInventory") CarriedInventory<?> container) {
if (!container.getName().get().equals("Furnace")) {
return;
}
final Carrier carrier = container.getCarrier().orElse(null);
if (!(carrier instanceof Furnace)) {
return;
}
final Furnace furnace = (Furnace) carrier;
final int passed = furnace.passedBurnTime().get();
final int max = furnace.maxBurnTime().get();
if (max <= 0 || passed >= max) {
return;
}
for (SlotTransaction transaction : event.getTransactions()) {
if (container.getInventoryProperty(transaction.getSlot(), SlotIndex.class).get().getValue() == 0) {
if (transaction.getFinal().getType() == ItemTypes.DIRT) {
player.getProgress(this.cookDirtAdvancement).grant();
} else if (this.suicidalAdvancement != null && (transaction.getFinal().getType() == ItemTypes.TNT ||
transaction.getFinal().getType() == ItemTypes.TNT_MINECART)) {
player.getProgress(this.suicidalAdvancement).grant();
/*
final Explosion explosion = Explosion.builder()
.location(furnace.getLocation())
.shouldBreakBlocks(true)
.canCauseFire(true)
.shouldDamageEntities(true)
.radius(7)
.build();
explosion.getWorld().triggerExplosion(explosion);
*/
}
}
}
}
示例7: LanternImmutableInventoryItemData
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
public LanternImmutableInventoryItemData(InventoryItemData manipulator) {
super(manipulator);
final Element<CarriedInventory<?>> element = getValueCollection().getElement(LanternKeys.ITEM_INVENTORY).get();
if (element.get() instanceof LanternEmptyCarriedInventory) {
element.set(new LanternEmptyCarriedInventory(this));
}
}
示例8: LanternInventoryItemData
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
protected LanternInventoryItemData(IDataManipulatorBase<InventoryItemData, ImmutableInventoryItemData> manipulator) {
super(manipulator);
final Element<CarriedInventory<?>> element = getValueCollection().getElement(LanternKeys.ITEM_INVENTORY).get();
if (element.get() instanceof LanternEmptyCarriedInventory) {
element.set(new LanternEmptyCarriedInventory(this));
}
}
示例9: onCloseInventory
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener
public void onCloseInventory(InteractInventoryEvent.Close event, @Root Player player, @Getter("getTargetInventory") Container inventory)
{
// When closing update filters and prompt activation
if (inventory instanceof CarriedInventory && inventory.size() > 0)
{
((CarriedInventory<?>) inventory).getCarrier().ifPresent(carrier -> this.promptActivation(carrier, true, player));
}
}
示例10: onOpenInventory
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener
public void onOpenInventory(InteractInventoryEvent.Open event, @Root Player player, @Getter("getTargetInventory") Container inventory)
{
// When opening prompt activation
if (inventory instanceof CarriedInventory && inventory.size() > 0)
{
((CarriedInventory<?>) inventory).getCarrier().ifPresent(carrier -> this.promptActivation(carrier, false, player));
}
}
示例11: onTransferInventory
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener
public void onTransferInventory(ChangeInventoryEvent.Transfer.Pre event, @Getter("getTargetInventory") Container inventory)
{
// When getting items transferred prompt activation
if (inventory instanceof CarriedInventory && inventory.size() > 0)
{
((CarriedInventory<?>) inventory).getCarrier().ifPresent(c -> this.promptActivation(c, true, null));
}
}
示例12: onCloseInventory
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener
public void onCloseInventory(InteractInventoryEvent.Close event, @Root Player player, @Getter("getTargetInventory") Container inventory)
{
// When closing update filters
if (inventory instanceof CarriedInventory<?>) {
((CarriedInventory<?>) inventory).getCarrier().ifPresent(carrier -> {
if (carrier instanceof DuctFilterCarrier)
{
((DuctFilterCarrier) carrier).update(event.getTargetInventory().iterator().next());
}
});
}
}
示例13: openFilter
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
private void openFilter(Player player, DuctData ductData, Direction dir, Location<World> loc)
{
if (!player.hasPermission(viewFilterPerm.getId()))
{
i18n.send(ChatTypes.ACTION_BAR, player, NEGATIVE, "You are not allowed to edit filters");
return;
}
List<ItemStack> list = ductData.get(dir).get();
DuctFilterCarrier carrier = new DuctFilterCarrier(ductData, loc, dir);
boolean canEdit = player.hasPermission(editFilterPerm.getId());
Inventory inventory = Inventory.builder()
.property(InventoryTitle.PROPERTY_NAME,
InventoryTitle.of(canEdit ? i18n.translate(player, TextFormat.NONE, "ItemDuct Filters") :
i18n.translate(player, TextFormat.NONE, "View ItemDuct Filters")))
.withCarrier(carrier)
.build(plugin);
carrier.init(((CarriedInventory<?>) inventory));
for (ItemStack itemStack : list)
{
inventory.offer(itemStack);
}
Sponge.getCauseStackManager().pushCause(player);
if (canEdit)
{
player.openInventory(inventory);
}
else
{
igf.prepareInv(inventory, player.getUniqueId()).blockPutInAll().blockTakeOutAll().submitInventory(Itemduct.class, true);
}
player.getProgress(module.filters).grant();
}
示例14: onInventoryClose
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Listener
public void onInventoryClose(InteractInventoryEvent.Close event, @First Player player)
{
Container inventory = event.getTargetInventory();
if (inventory instanceof CarriedInventory)
{
if (((CarriedInventory)inventory).getCarrier().orElse(null) instanceof BackpackHolder)
{
BackpackHolder holder = (BackpackHolder)((CarriedInventory)inventory).getCarrier().get();
holder.getBackpack().closeInventory(inventory, player);
}
}
}
示例15: getHolder
import org.spongepowered.api.item.inventory.type.CarriedInventory; //导入依赖的package包/类
@Override
public InventoryHolder getHolder() {
if (this.getHandle() instanceof CarriedInventory) {
Optional<?> carrier = ((CarriedInventory) this.getHandle()).getCarrier();
if (carrier.isPresent()) {
return PoreInventoryHolder.of((Carrier) carrier.get());
}
}
return null;
}