当前位置: 首页>>代码示例>>Java>>正文


Java InventoryMoveItemEvent.getSource方法代码示例

本文整理汇总了Java中org.bukkit.event.inventory.InventoryMoveItemEvent.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java InventoryMoveItemEvent.getSource方法的具体用法?Java InventoryMoveItemEvent.getSource怎么用?Java InventoryMoveItemEvent.getSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.event.inventory.InventoryMoveItemEvent的用法示例。


在下文中一共展示了InventoryMoveItemEvent.getSource方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onInventoryMoveItemEvent

import org.bukkit.event.inventory.InventoryMoveItemEvent; //导入方法依赖的package包/类
/**
 * Prevent hoppers from removing or inserting items in death chests
 * @param event
 */
@EventHandler
public void onInventoryMoveItemEvent(InventoryMoveItemEvent event) {

	// get inventories involved in event
	Inventory destination = event.getDestination();
	Inventory source = event.getSource();
	
	// if source inventory is a death chest, cancel event and return
	if (inventoryIsDeathChest(source)) {
		event.setCancelled(true);
		return;
	}
	
	// if destination is a death chest and prevent-item-placement is true, cancel event and return
	if (inventoryIsDeathChest(destination) && plugin.getConfig().getBoolean("prevent-item-placement")) {
		event.setCancelled(true);
		return;
	}
}
 
开发者ID:tim-savage,项目名称:SavageDeathChest,代码行数:24,代码来源:InventoryEventListener.java

示例2: onMove

import org.bukkit.event.inventory.InventoryMoveItemEvent; //导入方法依赖的package包/类
@EventHandler
public void onMove(InventoryMoveItemEvent e) {
	if (e.getSource() == null) return;
	if (e.getSource().getTitle() == null) return;
	if (e.getSource().getTitle().equals(CC(Main.finalconfig.getString("atm_title")))) {
		e.setCancelled(true);
	}
}
 
开发者ID:mastercake10,项目名称:TimeIsMoney,代码行数:9,代码来源:ATM.java

示例3: onInventoryMoveItemEvent

import org.bukkit.event.inventory.InventoryMoveItemEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled=true)
public void onInventoryMoveItemEvent(InventoryMoveItemEvent event) {
    Inventory initiator = event.getInitiator();
    Inventory dest = event.getDestination();
    Inventory source = event.getSource();
    
    //Prevent items from being pulled out by other hopper
if(plugin.getConfig().getBoolean("preventitempull")){
    if(plugin.checkNames(source.getName()) && initiator != source){ 
        event.setCancelled(true);        
    }
}

    if(plugin.checkNames(initiator.getName())){   
        if(!initiator.contains(event.getItem().getType())) {
            
            event.setCancelled(true);
            
            //Try to move items in other slots
            if(dest != initiator) {
                for(int slot=1; slot < initiator.getSize(); slot++) {
                    if(this.MoveItem(initiator, slot, dest) == true){break;}
               }                
            }            
        }
    }
}
 
开发者ID:poiNt3D,项目名称:SortingHopper,代码行数:28,代码来源:HopperListener.java

示例4: onItemMove

import org.bukkit.event.inventory.InventoryMoveItemEvent; //导入方法依赖的package包/类
@EventHandler
public void onItemMove(InventoryMoveItemEvent event)
{
    Inventory source = event.getSource();
    Inventory target = event.getDestination();

    if (target == null || source == null)
    {
        this.module.getLog().warn("InventoryMoveItem has null {} -> {} This should never happen!", source, target);
        return;
    }
    Location sourceLocation = this.getLocationForHolder(source.getHolder());
    if (sourceLocation == null)
    {
        return;
    }
    Location targetLocation = this.getLocationForHolder(target.getHolder());
    if (targetLocation == null)
    {
        return;
    }
    ItemMove action = this.newAction(ItemMove.class, targetLocation.getWorld());
    if (action != null)
    {
        LoggingConfiguration config = this.getConfig(targetLocation.getWorld());
        if (config.container.moveIgnore.contains(event.getItem().getType()))
        {
            return;
        }
        action.item = event.getItem();
        action.setLocation(sourceLocation);
        action.direction = sourceLocation.getBlock().getFace(targetLocation.getBlock());
        action.fromContainer = new ContainerType(source.getHolder());
        action.toContainer = new ContainerType(target.getHolder());
        this.logAction(action);
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:38,代码来源:ListenerItemMove.java

示例5: onItemMove

import org.bukkit.event.inventory.InventoryMoveItemEvent; //导入方法依赖的package包/类
@EventHandler
public void onItemMove(InventoryMoveItemEvent event) {
	try {
		if (event.getDestination() != null && event.getDestination().equals(this.inventory)) {
			event.setCancelled(true);
		}
		if (event.getSource() != null && event.getSource().equals(this.inventory)) {
			event.setCancelled(true);
		}
	}
	catch (final Exception e) { CraftoMessenger.report(this, "Failed to handle item move event!", e); }
}
 
开发者ID:Craftolution,项目名称:CraftoPlugin,代码行数:13,代码来源:Menu.java

示例6: onInventoryMoveItem

import org.bukkit.event.inventory.InventoryMoveItemEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
void onInventoryMoveItem(InventoryMoveItemEvent event) {
	if (event.getSource() != null) {
		InventoryHolder holder = event.getSource().getHolder();
		if (holder != null && holder instanceof Chest) {
			Block block = ((Chest) holder).getBlock();
			if (plugin.getProtectedChests().isChestProtected(block, null)) {
				event.setCancelled(true);
			}
		}
	}
}
 
开发者ID:nisovin,项目名称:Shopkeepers,代码行数:13,代码来源:ChestProtectListener.java

示例7: onItemMove

import org.bukkit.event.inventory.InventoryMoveItemEvent; //导入方法依赖的package包/类
@EventHandler
public void onItemMove(InventoryMoveItemEvent event) {
	try {
		// Check for nulls
		if (event.getSource() == null || event.getSource().getHolder() == null) { return; }
		if (event.getDestination() == null || event.getDestination().getHolder() == null) { return; }

		// Debug
		debug("onItemMove(%s, %s, %s)", event.getItem().getType(), event.getSource().getHolder(),
				event.getDestination().getHolder());

		// Check if destination is a hopper minecart. If it isn't, the transaction is always valid.
		if (!(event.getDestination().getHolder() instanceof HopperMinecart)) {
			debug("onItemMove() returning because destination is not a HopperMinecart");
			return;
		}

		final HopperMinecart hopper = (HopperMinecart) event.getDestination().getHolder();
		final InventoryHolder source = event.getSource().getHolder();

		if (isValidSource(source)) {
			final Location sourceLocation = event.getSource().getLocation();
			if (sourceLocation == null) {
				error("Failed to find location of source InventoryHolder: %s", source);
				return;
			}

			final BlockProtection sourceProt = this.module.getProtection(sourceLocation).orElse(null);
			if (sourceProt == null) { debug("onItemMove() returning because sourceProt is null"); return; }

			// Check if destination hopper is also protected
			final EntityProtection destProt = this.module.getProtection(hopper.getUniqueId()).orElse(null);
			if (destProt == null) {
				// HopperMinecart is not protected, so we don't know from whom the hopper is coming
				// from. Because the source is protected, we have to protect its content from being
				// taken by an unknown minecrat. Therefore, the event needs to be cancelled.
				debug("onItemMove() returning because destProt is null");
				event.setCancelled(true);
				return;
			}

			// The HopperMinecart is protected, so we can check if the owner of that is allowed to
			// take items from the protected source
			StoredPlayer hopperOwner = destProt.getOwner();

			if (!this.module.isAllowedToInteract(sourceProt, hopperOwner)) {
				// Seems like the owner of the HopperMinecart is not allowed to interact with the source
				debug("onItemMove() cancelling because hopperOwner can not access sourecProt");
				event.setCancelled(true);
				return;
			}

		}

	}
	catch (Exception e) { report("Failed to handle InventoryMoveItemEvent", e); }
}
 
开发者ID:Craftolution,项目名称:CraftoPlugin,代码行数:58,代码来源:InteractionListener.java


注:本文中的org.bukkit.event.inventory.InventoryMoveItemEvent.getSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。