本文整理汇总了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;
}
}
示例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);
}
}
示例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;}
}
}
}
}
}
示例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);
}
}
示例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); }
}
示例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);
}
}
}
}
示例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); }
}