本文整理汇总了Java中org.spongepowered.api.event.item.inventory.InteractItemEvent类的典型用法代码示例。如果您正苦于以下问题:Java InteractItemEvent类的具体用法?Java InteractItemEvent怎么用?Java InteractItemEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InteractItemEvent类属于org.spongepowered.api.event.item.inventory包,在下文中一共展示了InteractItemEvent类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openItemCase
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void openItemCase(InteractItemEvent.Secondary.MainHand event) {
Optional<Player> optional_player = event.getCause().first(Player.class);
if (!optional_player.isPresent()) return;
Player player = optional_player.get();
ItemStack item = event.getItemStack().createStack();
for (Manager manager : GWMCrates.getInstance().getCreatedManagers()) {
Case caze = manager.getCase();
if (!(caze instanceof ItemCase)) continue;
ItemStack case_item = ((ItemCase) caze).getItem();
if (!Utils.itemStacksEquals(item, case_item)) continue;
event.setCancelled(true);
OpenManager open_manager = manager.getOpenManager();
if (!open_manager.canOpen(player, manager)) {
player.sendMessage(LanguageUtils.getText("CAN_NOT_OPEN_CASE"));
return;
}
Key key = manager.getKey();
if (key.get(player) < 1) {
player.sendMessage(LanguageUtils.getText("HAVE_NOT_KEY"));
return;
}
caze.add(player, -1);
key.add(player, -1);
manager.getOpenManager().open(player, manager);
break;
}
}
示例2: startItemCasePreview
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void startItemCasePreview(InteractItemEvent.Primary.MainHand event) {
Optional<Player> optional_player = event.getCause().first(Player.class);
if (!optional_player.isPresent()) return;
Player player = optional_player.get();
ItemStack item = event.getItemStack().createStack();
for (Manager manager : GWMCrates.getInstance().getCreatedManagers()) {
String manager_id = manager.getId();
Case caze = manager.getCase();
if (!(caze instanceof ItemCase)) continue;
ItemStack case_item = ((ItemCase) caze).getItem();
if (!Utils.itemStacksEquals(item, case_item)) continue;
event.setCancelled(true);
if (!((ItemCase) caze).isStartPreviewOnLeftClick()) return;
Optional<Preview> optional_preview = manager.getPreview();
if (!optional_preview.isPresent()) {
player.sendMessage(LanguageUtils.getText("PREVIEW_NOT_AVAILABLE",
new Pair<String, String>("%MANAGER%", manager.getName())));
return;
}
Preview preview = optional_preview.get();
if (!player.hasPermission("gwm_crates.preview." + manager_id)) {
player.sendMessage(LanguageUtils.getText("HAVE_NOT_PERMISSION"));
return;
}
preview.preview(player, manager);
player.sendMessage(LanguageUtils.getText("PREVIEW_STARTED",
new Pair<String, String>("%MANAGER%", manager.getName())));
break;
}
}
示例3: onInteractItemPrimary
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener(order = Order.EARLY)
public void onInteractItemPrimary(InteractItemEvent.Primary event, @First Player player)
{
String name = "";
Optional<VirtualChestInventory> inventoryOptional = Optional.empty();
for (String inventoryName : this.dispatcher.listInventories())
{
VirtualChestInventory inventory = this.dispatcher.getInventory(inventoryName).get();
if (inventory.matchItemForOpeningWithPrimaryAction(event.getItemStack()))
{
if (player.hasPermission("virtualchest.open.self." + inventoryName))
{
name = inventoryName;
inventoryOptional = Optional.of(inventory);
event.setCancelled(true);
break;
}
}
}
if (inventoryOptional.isPresent())
{
try
{
this.logger.debug("Player {} tries to create the GUI ({}) by primary action", player.getName(), name);
SpongeUnimplemented.openInventory(player, inventoryOptional.get().createInventory(player), this);
}
catch (InvalidDataException e)
{
this.logger.error("There is something wrong with the GUI configuration (" + name + ")", e);
}
}
}
示例4: onInteractItemSecondary
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener(order = Order.EARLY)
public void onInteractItemSecondary(InteractItemEvent.Secondary event, @First Player player)
{
String name = "";
Optional<VirtualChestInventory> inventoryOptional = Optional.empty();
for (String inventoryName : this.dispatcher.listInventories())
{
VirtualChestInventory inventory = this.dispatcher.getInventory(inventoryName).get();
if (inventory.matchItemForOpeningWithSecondaryAction(event.getItemStack()))
{
if (player.hasPermission("virtualchest.open.self." + inventoryName))
{
name = inventoryName;
inventoryOptional = Optional.of(inventory);
event.setCancelled(true);
break;
}
}
}
if (inventoryOptional.isPresent())
{
try
{
this.logger.debug("Player {} tries to create the GUI ({}) by secondary action", player.getName(), name);
SpongeUnimplemented.openInventory(player, inventoryOptional.get().createInventory(player), this);
}
catch (InvalidDataException e)
{
this.logger.error("There is something wrong with the GUI configuration (" + name + ")", e);
}
}
}
示例5: onLeftClick
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
public void onLeftClick(InteractItemEvent.Primary evt, @Root Player player) {
PlayerLeftClicksScriptEvent event = (PlayerLeftClicksScriptEvent) clone();
event.internal = evt;
event.player = new PlayerTag(player);
event.cancelled = evt.isCancelled();
event.run();
evt.setCancelled(event.cancelled);
}
示例6: onRightClick
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
public void onRightClick(InteractItemEvent.Secondary evt, @Root Player player) {
PlayerRightClicksScriptEvent event = (PlayerRightClicksScriptEvent) clone();
event.internal = evt;
event.player = new PlayerTag(player);
event.cancelled = evt.isCancelled();
event.run();
evt.setCancelled(event.cancelled);
}
示例7: onPlayerInteract
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener(order=Order.LAST)
public void onPlayerInteract(InteractItemEvent.Secondary event, @First Player player_sponge) {
EPlayer player = this.plugin.getEServer().getEPlayer(player_sponge);
if(player.getItemInMainHand().isPresent()){
ItemStack item = player.getItemInMainHand().get();
if(item.getType().equals(ItemTypes.COMPASS) && player.isCreative()){
Optional<Vector3i> block = player.getViewBlock();
if (block.isPresent()) {
player.teleport(player.getWorld().getLocation(block.get().add(0, 1, 0)), true);
}
}
}
}
示例8: onRMBClick
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
@Include({
InteractBlockEvent.Secondary.class,
InteractEntityEvent.Secondary.class,
InteractItemEvent.Secondary.class
})
public void onRMBClick(InteractEvent e, @Root Player player) {
IActiveCharacter character = characterService.getCharacter(player);
e.setCancelled(characterService.processUserAction(character, UserActionType.R));
}
示例9: onLMBClick
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
@Include({
InteractBlockEvent.Primary.class,
InteractEntityEvent.Primary.class,
InteractItemEvent.Primary.class
})
public void onLMBClick(InteractEvent e, @Root Player player) {
IActiveCharacter character = characterService.getCharacter(player);
e.setCancelled(characterService.processUserAction(character, UserActionType.L));
}
示例10: onItemUse
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
public void onItemUse(InteractItemEvent event) {
if (blockedItems.contains(event.getItemStack().getType().getId())) {
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
player.sendMessage(Text.of(TextColors.RED, "This item has been disabled."));
}
event.setCancelled(true);
}
}
示例11: onUseItem
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
public void onUseItem(InteractItemEvent.Secondary event, @Root Player player)
{
ItemType item = event.getItemStack().getType();
List<Region> regionsAt = manager.getRegionsAt(player.getLocation());
Permission usePerm = pm.register(SettingsListener.class, item.getId(), "Allows interacting with a " + item.getTranslation().get() + " Item in hand", useItemPerm);
Tristate set = checkSetting(event, player, regionsAt, () -> usePermission.get(UseType.ITEM), s -> s.use.all.item, UNDEFINED);
if (checkSetting(event, player, regionsAt, () -> usePerm, (s) -> s.use.item.getOrDefault(item, UNDEFINED), set) == FALSE)
{
i18n.send(ACTION_BAR, player, CRITICAL, "You are not allowed to use this here.");
}
}
示例12: onCancelRepair
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
public void onCancelRepair(InteractEvent event, @First Player player)
{
if (event instanceof InteractBlockEvent || event instanceof InteractItemEvent)
{
return;
}
this.cancelRequest(event, player);
}
示例13: onInteract
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener
public void onInteract(InteractItemEvent event) {
ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
CommentedConfigurationNode hnode = config.get();
ItemStackSnapshot item = event.getItemStack();
CommentedConfigurationNode node = hnode.getNode("items", item.getType().getId());
if (!node.isVirtual()) {
if (node.getNode("deny-use").getBoolean()) {
event.setCancelled(true);
}
}
}
示例14: onItemInteract
import org.spongepowered.api.event.item.inventory.InteractItemEvent; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onItemInteract(InteractItemEvent interactItemEvent, @First Player player) {
checkLoginStatus(interactItemEvent, player);
}