本文整理汇总了Java中org.spongepowered.api.event.item.inventory.InteractInventoryEvent类的典型用法代码示例。如果您正苦于以下问题:Java InteractInventoryEvent类的具体用法?Java InteractInventoryEvent怎么用?Java InteractInventoryEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InteractInventoryEvent类属于org.spongepowered.api.event.item.inventory包,在下文中一共展示了InteractInventoryEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInventory
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Override
public Inventory getInventory() {
Inventory woop = Inventory.builder()
.property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9,1))
.property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(Text.of(TextColors.DARK_RED,"INVALID CRATE TYPE!")))
.listener(InteractInventoryEvent.class, evt ->{
if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof InteractInventoryEvent.Close)){
evt.setCancelled(true);
}
//System.out.println(evt.getClass());
})
.build(plugin);
woop.offer(ItemStack.of(ItemTypes.BARRIER,256*2 + 64));
for(Inventory e : woop.slots()){
ItemStack b = e.peek().get();
b.setQuantity(1);
e.set(b);
}
return woop;
}
示例2: createInventory
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
public Inventory createInventory(Player player)
{
UUID uuid = player.getUniqueId();
if (!inventories.containsKey(uuid))
{
VirtualChestEventListener listener = new VirtualChestEventListener(player);
Inventory chestInventory = Inventory.builder().of(InventoryArchetypes.CHEST).withCarrier(player)
.property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(this.title))
.property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, this.height))
.listener(ClickInventoryEvent.class, listener::fireClickEvent)
.listener(InteractInventoryEvent.Open.class, listener::fireOpenEvent)
.listener(InteractInventoryEvent.Close.class, listener::fireCloseEvent)
.build(this.plugin);
inventories.put(uuid, chestInventory);
return chestInventory;
}
return inventories.get(uuid);
}
示例3: create
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Override
public SimpleCustomInventory create(DataHolder dataHolder) {
SimpleCustomInventory result = new SimpleCustomInventory(this, dataHolder);
String typeId = getTypeId();
InventoryArchetype archetype = InventoryArchetype.builder()
.with(InventoryArchetypes.DOUBLE_CHEST)
.property(new InventoryDimension(INVENTORY_SLOTS_WIDTH, getHeight()))
.build(typeId, typeId);
Inventory inventory = Inventory.builder()
.of(archetype)
.listener(InteractInventoryEvent.class, result)
.build(CustomItemLibrary.getInstance());
result.setInventory(inventory);
populate(result);
return result;
}
示例4: onInteractInventoryEventClose
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Listener
public void onInteractInventoryEventClose(InteractInventoryEvent.Close event) throws IOException, SQLException {
final Container container = (Container) event.getTargetInventory();
if (container instanceof ContainerChest) {
final ContainerChest containerChest = (ContainerChest) container;
if (containerChest.getLowerChestInventory() instanceof BackpackInventory) {
final BackpackInventory inventory = (BackpackInventory) containerChest.getLowerChestInventory();
final Backpacks record = inventory.getRecord();
final Session session = DatabaseManager.getSessionFactory().openSession();
session.beginTransaction();
for (int i = 0; i < record.getSize(); i++) {
final ItemStack stack = (ItemStack) (Object) inventory.getStackInSlot(i);
DatabaseManager.saveSlot(session, record, i, stack == null ? null : stack.toContainer());
}
session.getTransaction().commit();
session.close();
}
}
}
示例5: onInventoryOpen
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的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);
}
示例6: manageClose
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Listener
public void manageClose(InteractInventoryEvent.Close event) {
Container container = event.getTargetInventory();
if (FirstGuiPreview.FIRST_GUI_CONTAINERS.containsKey(container)) {
FirstGuiPreview.FIRST_GUI_CONTAINERS.remove(container);
} else if (SecondGuiPreview.SECOND_GUI_CONTAINERS.containsKey(container)) {
SecondGuiPreview.SECOND_GUI_CONTAINERS.remove(container);
}
}
示例7: cancelClose
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Listener
public void cancelClose(InteractInventoryEvent.Close event) {
Container container = event.getTargetInventory();
if (!FirstOpenManager.SHOWN_GUI.contains(container) &&
FirstOpenManager.FIRST_GUI_CONTAINERS.containsKey(container) &&
FirstOpenManager.FIRST_GUI_CONTAINERS.get(container).getKey().isForbidClose()) {
event.setCancelled(true);
}
}
示例8: RouletteCrateView
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
public RouletteCrateView(HuskyCrates plugin, Player runner, VirtualCrate virtualCrate){
this.plugin = plugin;
vc = virtualCrate;
ourplr = runner;
items = vc.getItemSet();
if(virtualCrate.scrambleRewards){
scrambleRewards();
}
disp = Inventory.builder()
.of(InventoryArchetypes.DISPENSER)
.listener(InteractInventoryEvent.class, evt ->{
if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof InteractInventoryEvent.Close)){
evt.setCancelled(true);
if(!stopped && evt instanceof ClickInventoryEvent){
ourplr.playSound(SoundTypes.ENTITY_FIREWORK_LAUNCH,ourplr.getLocation().getPosition(),1);
}
stopped = true;
}
})
.property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName)))
.build(plugin);
updateInv(0);
Scheduler scheduler = Sponge.getScheduler();
Task.Builder taskBuilder = scheduler.createTaskBuilder();
updater = taskBuilder.execute(this::updateTick).intervalTicks(1).submit(plugin);
}
示例9: InstantGUIView
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
public InstantGUIView(HuskyCrates plugin, Player runner, VirtualCrate virtualCrate){
//System.out.println("AA");
this.plugin = plugin;
vc = virtualCrate;
ourplr = runner;
items = vc.getItemSet();
if(virtualCrate.scrambleRewards){
scrambleRewards();
}
disp = Inventory.builder()
.of(InventoryArchetypes.DISPENSER)
.listener(InteractInventoryEvent.class, evt ->{
if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof InteractInventoryEvent.Close)){
evt.setCancelled(true);
}
})
.property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName)))
.build(plugin);
updateInv(0);
Scheduler scheduler = Sponge.getScheduler();
Task.Builder taskBuilder = scheduler.createTaskBuilder();
updater = taskBuilder.execute(this::updateTick).intervalTicks(1).submit(plugin);
scheduler.createTaskBuilder().execute(() -> {
updater.cancel();
ourplr.closeInventory();
handleReward(holder);
ourplr.playSound(SoundTypes.ENTITY_EXPERIENCE_ORB_PICKUP,ourplr.getLocation().getPosition(),1);
}).delay(3, TimeUnit.SECONDS).submit(HuskyCrates.instance);
}
示例10: onClickInventory
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Listener
public void onClickInventory(InteractInventoryEvent event, @Root @Has(ViewerData.class) Player player) {
Optional<String> camId = player.get(VigilateKeys.CAMERA);
if(camId.isPresent() && Vigilate.getInstance().getCameras().containsKey(camId.get())){
Vigilate.getInstance().getCameras().get(camId.get()).endViewCamera(player);
} else {
Camera.resetPlayer(player);
}
event.setCancelled(true);
}
示例11: fireOpenEvent
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
private void fireOpenEvent(InteractInventoryEvent.Open e)
{
Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId);
if (optional.isPresent())
{
Player player = optional.get();
Container targetContainer = e.getTargetInventory();
Inventory targetInventory = targetContainer.first();
plugin.getVirtualChestActions().submitCommands(player, parsedOpenAction, ImmutableList.of());
if (updateIntervalTick > 0)
{
Task.Builder builder = Sponge.getScheduler().createTaskBuilder().execute(task ->
{
if (player.getOpenInventory().filter(targetContainer::equals).isPresent())
{
refreshMappingFrom(targetInventory, updateInventory(player, targetInventory));
}
else
{
task.cancel();
}
});
builder.delayTicks(updateIntervalTick).intervalTicks(updateIntervalTick).submit(plugin);
}
logger.debug("Player {} opens the chest GUI", player.getName());
plugin.getScriptManager().onOpeningInventory(player);
refreshMappingFrom(targetInventory, updateInventory(player, targetInventory));
}
}
示例12: fireCloseEvent
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
private void fireCloseEvent(InteractInventoryEvent.Close e)
{
Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId);
if (optional.isPresent())
{
Player player = optional.get();
plugin.getVirtualChestActions().submitCommands(player, parsedCloseAction, ImmutableList.of());
logger.debug("Player {} closes the chest GUI", player.getName());
actionIntervalManager.onClosingInventory(player);
}
}
示例13: onPlayerInteractInventory
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Listener
public void onPlayerInteractInventory(InteractInventoryEvent event, @First Player player_sponge) {
EPlayer player = this.plugin.getEServer().getEPlayer(player_sponge);
// AFK
player.updateLastActivated();
}
示例14: onInventoryClosed
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Listener
public void onInventoryClosed(InteractInventoryEvent.Close event) {
Optional<Player> cause = event.getCause().first(Player.class);
if (cause.isPresent()) {
UUID target = cause.get().getUniqueId();
VillagerShops.openShops.remove(target);
VillagerShops.actionUnstack.remove(target);
// l("%s closed an inventory", cause.get().getName());
} else {
// l("An inventory was closed");
}
}
示例15: onInventoryOpened
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; //导入依赖的package包/类
@Listener
public void onInventoryOpened(InteractInventoryEvent.Open event) {
Optional<Player> cause = event.getCause().first(Player.class);
if (cause.isPresent()) {
// openShops.remove(cause.get().getUniqueId());
// VillagerShops.l("%s opened and inventory %s", cause.get().getName(), event.getTargetInventory().getName());
} else {
// VillagerShops.w("Can't get player opening inventory");
}
}