本文整理汇总了Java中org.spongepowered.api.item.inventory.InventoryArchetypes类的典型用法代码示例。如果您正苦于以下问题:Java InventoryArchetypes类的具体用法?Java InventoryArchetypes怎么用?Java InventoryArchetypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InventoryArchetypes类属于org.spongepowered.api.item.inventory包,在下文中一共展示了InventoryArchetypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
@Override
public void open(Player player, Manager manager) {
PlayerOpenCrateEvent open_event = new PlayerOpenCrateEvent(player, manager);
Sponge.getEventManager().post(open_event);
if (open_event.isCancelled()) return;
Inventory inventory = display_name.map(text -> Inventory.builder().of(InventoryArchetypes.CHEST).
property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(text)).
build(GWMCrates.getInstance())).orElseGet(() -> Inventory.builder().of(InventoryArchetypes.CHEST).
property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
build(GWMCrates.getInstance()));
OrderedInventory ordered = Utils.castToOrdered(inventory);
int hidden_item_quantity = hidden_item.getQuantity();
for (int i = 0; i < 9 * rows; i++) {
int quantity = increase_hidden_item_quantity ? i + 1 : hidden_item_quantity;
ItemStack copy = hidden_item.copy();
copy.setQuantity(quantity);
ordered.getSlot(new SlotIndex(i)).get().set(copy);
}
Container container = player.openInventory(inventory).get();
getOpenSound().ifPresent(open_sound -> player.playSound(open_sound, player.getLocation().getPosition(), 1.));
SECOND_GUI_INVENTORIES.put(container, new Pair<SecondOpenManager, Manager>(this, manager));
}
示例2: getAddTrailCommand
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
private static CommandSpec getAddTrailCommand() {
return CommandSpec.builder()
.permission("happytrails.command.add")
.description(Text.of("Adds a new trail"))
.executor((src, args) -> {
if (!(src instanceof Player)) {
return CommandResult.empty();
}
final Inventory creator = Inventory.builder()
.of(InventoryArchetypes.CHEST)
.property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(Text.of(TextColors.AQUA, "Create a Trail")))
.listener(ClickInventoryEvent.Primary.class, (event) -> {
})
.build(HappyTrails.getInstance());
creator.offer(ItemStack.of(ItemTypes.FIREWORKS, 1));
creator.offer(ItemStack.builder().fromBlockState(BlockTypes.REDSTONE_BLOCK.getDefaultState()).build());
((Player) src).openInventory(creator);
return CommandResult.success();
})
.build();
}
示例3: onItemEquip
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
@Listener
public void onItemEquip(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER) {
Inventory equipmentSlots = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentSlot.class));
equipmentSlots.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.equip." + itemId + ".on.self")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemType.getName() + '!'));
}
}));
}
}
示例4: onItemCraft
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
@Listener
public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {
Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class));
craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.craft." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!'));
}
}));
}
}
示例5: create
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的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;
}
示例6: displayAttributes
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
@Override
public void displayAttributes(Player player, PlayerGroup group) {
Inventory i = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).build(plugin);
i.query(new SlotPos(0, 0)).offer(back(group));
int x = 1;
int y = 1;
for (Map.Entry<ICharacterAttribute, Integer> a : group.getStartingAttributes().entrySet()) {
ICharacterAttribute key = a.getKey();
Integer value = a.getValue();
i.query(new SlotPos(x, y)).offer(createAttributeItem(key, value));
//somehow format them in square-like structure
if (x == 7) {
x = 1;
y++;
} else {
x++;
}
}
player.openInventory(i);
}
示例7: displayRunewordAllowedItems
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
@Override
public void displayRunewordAllowedItems(IActiveCharacter character, RuneWord rw) {
Inventory i = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).build(plugin);
i.query(new SlotPos(0, 0)).offer(back("runeword " + rw.getName(), Localization.RUNEWORD_DETAILS_MENU));
int x = 1;
int y = 2;
for (ItemType type : rw.getAllowedItems()) {
i.query(new SlotPos(x, y)).offer(GuiHelper.itemStack(type));
if (x == 7) {
x = 1;
y++;
} else {
x++;
}
}
}
示例8: displayGroupRequirements
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
private Inventory displayGroupRequirements(IActiveCharacter character, RuneWord rw, Set<PlayerGroup> groups) {
Inventory i = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).build(plugin);
String cmd = infoCommand.getAliases().get(0);
i.query(new SlotPos(0, 0)).offer(back("runeword " + rw.getName(), Localization.RUNEWORD_DETAILS_MENU));
List<ItemStack> list = new ArrayList<>();
for (PlayerGroup playerGroup : groups) {
list.add(runewordRequirementsToItemStack(character, playerGroup));
}
int x = 1;
int y = 2;
for (ItemStack itemStack : list) {
i.query(new SlotPos(x, y)).offer(itemStack);
if (x == 7) {
x = 1;
y++;
} else {
x++;
}
}
return i;
}
示例9: getInventory
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
public RepairBlockInventory getInventory(final Player player)
{
if (player == null)
{
return null;
}
RepairBlockInventory inventory = this.inventoryMap.get(player.getName());
if (inventory == null)
{
Inventory inv = Inventory.builder().of(InventoryArchetypes.CHEST)
.property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9,4))
.property(InventoryCapacity.class.getSimpleName().toLowerCase(), InventoryCapacity.of(9*4))
.property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(getTitle())))
.build(module.getPlugin());
inventory = new RepairBlockInventory(inv, player);
this.inventoryMap.put(player.getName(), inventory);
}
return inventory;
}
示例10: preview
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
@Override
public void preview(Player player, Manager manager) {
Inventory inventory = display_name.map(text -> Inventory.builder().of(InventoryArchetypes.CHEST).
property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(text)).
build(GWMCrates.getInstance())).orElseGet(() -> Inventory.builder().of(InventoryArchetypes.CHEST).
build(GWMCrates.getInstance()));
OrderedInventory ordered = Utils.castToOrdered(inventory);
for (int i = 0; i < 10; i++) {
ordered.getSlot(new SlotIndex(i)).get().set(decorative_items.get(i));
}
List<Drop> drops = manager.getDrops();
int index = 0;
for (int i = 10; i < 17; i++) {
if (index > drops.size() - 1) {
index = 0;
}
ordered.getSlot(new SlotIndex(i)).get().set(drops.get(index).getDropItem().orElse(ItemStack.of(ItemTypes.NONE, 1)));
index++;
}
for (int i = 17; i < 27; i++) {
ordered.getSlot(new SlotIndex(i)).get().set(decorative_items.get(i - 7));
}
Container container = player.openInventory(inventory).get();
FIRST_GUI_CONTAINERS.put(container, new Pair<FirstGuiPreview, Manager>(this, manager));
decorative_items_change_mode.ifPresent(mode -> Sponge.getScheduler().
createTaskBuilder().delayTicks(mode.getChangeDelay()).
execute(new FirstOpenManager.DropChangeRunnable(player, container, ordered, new ArrayList<ItemStack>(decorative_items), mode)).
submit(GWMCrates.getInstance()));
Sponge.getScheduler().createTaskBuilder().delayTicks(scroll_delay).
execute(new DropChangeRunnable(container, drops, index)).
submit(GWMCrates.getInstance());
}
示例11: RouletteCrateView
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的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);
}
示例12: InstantGUIView
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的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);
}
示例13: onItemSmelt
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
@Listener
public void onItemSmelt(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.FURNACE) {
Inventory smeltingInputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(InputSlot.class));
PermHandler ph = PermHandler.getInstance();
smeltingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
if (slot instanceof FuelSlot) {
if (!ph.checkPerm(player, "protectionperms.item.fuel." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + " as fuel!"));
}
} else {
if (!ph.checkPerm(player, "protectionperms.item.smelt." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to smelt " + itemType.getName() + '!'));
}
}
}));
}
}
示例14: getInventory
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
/** @param forPlayer translate items descriptions for this player if applicable */
public Inventory getInventory(UUID forPlayer) {
ShopInventoryListener sil = new ShopInventoryListener(this);
Inventory.Builder builder = Inventory.builder().of(InventoryArchetypes.CHEST)
.property("inventorytitle", new InventoryTitle(Text.of(TextColors.DARK_AQUA,
VillagerShops.getTranslator().localText("shop.title")
.replace("%name%", Text.of(TextColors.RESET, displayName==null?Text.of():displayName))
.resolve(forPlayer).orElse(Text.of("[vShop] ", displayName==null?Text.of():displayName)))
))
.listener(ClickInventoryEvent.class, sil);
Inventory inv = preparator.getInventory(builder, forPlayer);
return inv;
}
示例15: displayCommonMenu
import org.spongepowered.api.item.inventory.InventoryArchetypes; //导入依赖的package包/类
private void displayCommonMenu(IActiveCharacter character, Collection<? extends PlayerGroup> g, PlayerGroup default_) {
Inventory i = Inventory.builder()
.of(InventoryArchetypes.DOUBLE_CHEST)
.build(plugin);
for (PlayerGroup cc : g) {
if (cc == default_) {
continue;
}
if (!cc.isShowsInMenu() && !character.getPlayer().hasPermission("ntrpg.admin")) {
continue;
}
i.offer(createItemRepresentingGroup(cc));
}
character.getPlayer().openInventory(i);
}