本文整理匯總了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); }
}