Java Code Examples for org.bukkit.event.player.PlayerInteractEntityEvent#getRightClicked()

The following examples show how to use org.bukkit.event.player.PlayerInteractEntityEvent#getRightClicked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameRotate(PlayerInteractEntityEvent event) {
    if(event.getRightClicked() instanceof ItemFrame) {
        ItemFrame itemFrame = (ItemFrame) event.getRightClicked();
        if(itemFrame.getItem() != null) {
            // If frame contains an item, right-click will rotate it, which is handled as a "use" event
            this.handleUse(event, getHangingBlockState(itemFrame), this.match.getParticipant(event.getPlayer()));
        } else if(event.getPlayer().getItemInHand() != null) {
            // If the frame is empty and it's right clicked with an item, this will place the item in the frame,
            // which is handled as a "place" event, with the placed item as the block material
            BlockState blockState = BlockStateUtils.cloneWithMaterial(itemFrame.getLocation().getBlock(),
                                                                      event.getPlayer().getItemInHand().getData());
            this.handleHangingPlace(event, blockState, event.getPlayer());
        }
    }
}
 
Example 2
Source File: KissCommand.java    From MarriageMaster with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
{
	if((!MCVersion.isDualWieldingMC() || event.getHand().equals(EquipmentSlot.HAND)) && event.getPlayer().isSneaking() && event.getPlayer().hasPermission(Permissions.KISS) && event.getRightClicked() instanceof Player)
	{
		MarriagePlayer player = getMarriagePlugin().getPlayerData(event.getPlayer());
		Long time = wait.get(player);
		if(time == null || time < System.currentTimeMillis() - waitTime)
		{
			MarriagePlayer player2 = getMarriagePlugin().getPlayerData((Player) event.getRightClicked());
			if(player.isPartner(player2) && getMarriagePlugin().isInRangeSquared(event.getPlayer(), (Player) event.getRightClicked(), interactRange))
			{
				kiss(player, player2);
			}
		}
	}
}
 
Example 3
Source File: MultiTradeMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInteract(PlayerInteractEntityEvent event) {
  if (event.getRightClicked() instanceof Villager) {
    // Fallback to once-at-a-time trading if multi trade does not work
    if (ok) {
      event.setCancelled(true);
    } else {
      return;
    }

    try {
      InventoryUtils.openVillager((Villager) event.getRightClicked(), event.getPlayer());
    } catch (NoSuchMethodError e) {
      logger.log(Level.WARNING, "<multitrade/> is not compatible with your server version");
      ok = false;
    } catch (Throwable t) {
      logger.log(
          Level.WARNING,
          String.format(
              "Villager at (%s) has invalid NBT data",
              event.getRightClicked().getLocation().toVector()),
          t);
      ok = false;
    }
  }
}
 
Example 4
Source File: PetOwnerListener.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    Player p = event.getPlayer();
    Entity e = event.getRightClicked();
    if (p.getItemInHand() != null && p.getItemInHand().isSimilar(SelectorLayout.getSelectorItem())) {
        SelectorLayout.getSelectorMenu().showTo(p);
        event.setCancelled(true);
        return;
    }

    if (ReflectionUtil.getEntityHandle(e) instanceof IEntityPet) {
        IPet pet = ((IEntityPet) ReflectionUtil.getEntityHandle(e)).getPet();
        event.setCancelled(true);
        PetInteractEvent iEvent = new PetInteractEvent(pet, p, PetInteractEvent.Action.RIGHT_CLICK, false);
        EchoPet.getPlugin().getServer().getPluginManager().callEvent(iEvent);
        if (!iEvent.isCancelled()) {
            pet.getEntityPet().onInteract(p);
            return;
        }
    }
}
 
Example 5
Source File: StickInteractEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onStickInteract(PlayerInteractEntityEvent event){
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    if(!(entity instanceof Mob)){
        return;
    }
    if(event.getHand() != EquipmentSlot.HAND) {
        return;
    }
    if (sm.getStickTools().isStackingStick(player.getInventory().getItemInMainHand())) {
        if (player.isSneaking()) {
            sm.getStickTools().toggleMode(player);
        } else {
            if(!(StackTools.hasValidMetadata(player, GlobalValues.STICK_MODE))){
                player.setMetadata(GlobalValues.STICK_MODE, new FixedMetadataValue(sm, 1));
            }
            sm.getStickTools().performAction(player, entity);
        }
    }
}
 
Example 6
Source File: EntityInteract.java    From FunnyGuilds with Apache License 2.0 6 votes vote down vote up
@EventHandler
public void onInteract(PlayerInteractEntityEvent event) {
    MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration();
    PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration();
    Player eventCaller = event.getPlayer();
    Entity clickedEntity = event.getRightClicked();

    if (clickedEntity instanceof Player) {
        Player clickedPlayer = (Player) clickedEntity;
        if (!config.infoPlayerEnabled || (config.infoPlayerSneaking && !eventCaller.isSneaking())
                        || informationMessageCooldowns.cooldown(eventCaller, TimeUnit.SECONDS, config.infoPlayerCooldown)) {
            return;
        }

        if (config.infoPlayerCommand) {
            playerExecutor.execute(eventCaller, new String[]{clickedPlayer.getName()});
        } else {
            playerExecutor.sendInfoMessage(messages.playerRightClickInfo, User.get(clickedPlayer), eventCaller);
        }
    }
}
 
Example 7
Source File: TNTSheepListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteractOtherUser(PlayerInteractEntityEvent event) {
  if (event.getPlayer() == null) {
    return;
  }

  Player player = event.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  if (event.getRightClicked() == null) {
    return;
  }

  if (event.getRightClicked() instanceof ITNTSheep) {
    event.setCancelled(true);
    return;
  }

  if (event.getRightClicked().getVehicle() != null
      && event.getRightClicked().getVehicle() instanceof ITNTSheep) {
    event.setCancelled(true);
    return;
  }
}
 
Example 8
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    if (event.getRightClicked() instanceof ItemFrame && ArmorStandTool.isHoldingTool(event.getPlayer())) {
        event.setCancelled(true);
        //noinspection deprecation
        event.getPlayer().updateInventory();
    }
}
 
Example 9
Source File: TntDefuse.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerRightClick(PlayerInteractEntityEvent event) {
    if (event.getRightClicked() instanceof TNTPrimed && event.getPlayer().getItemInHand() != null && event.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) {
        if (TntTracker.getWhoPlaced(event.getRightClicked()) != null) {
            UUID player = TntTracker.getWhoPlaced(event.getRightClicked());
            Optional<TeamModule> playerTeam = Teams.getTeamByPlayer(Bukkit.getPlayer(player));
            if (Bukkit.getOfflinePlayer(player).isOnline()) {
                if (event.getPlayer().hasPermission("tnt.defuse") || Teams.getTeamByPlayer(Bukkit.getPlayer(player)).orNull() == Teams.getTeamByPlayer(event.getPlayer()).orNull()) {
                    if (!event.getRightClicked().getLocation().getBlock().isLiquid()) {
                        if (!Bukkit.getPlayer(player).equals(event.getPlayer())) {
                            event.getRightClicked().remove();
                            ChatColor color = Teams.getTeamColorByPlayer(Bukkit.getOfflinePlayer(player));
                            event.getPlayer().sendMessage(ChatColor.RED + "You defused " + color + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RED + "'s TNT.");
                            ChatChannel channel = GameHandler.getGameHandler().getMatch().getModules().getModule(AdminChannel.class);
                            channel.sendMessage("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + Teams.getTeamColorByPlayer(event.getPlayer()) + event.getPlayer().getDisplayName() + ChatColor.RESET + " defused " + color + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RESET + "'s " + ChatColor.DARK_RED + "TNT");
                        }
                    } else {
                        ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse TNT in water!");
                    }
                } else {
                    ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT.");
                }
            } else {
                ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT.");
            }
        }
    }
}
 
Example 10
Source File: VillagerInteractionListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
void onEntityInteract(PlayerInteractEntityEvent event) {
	if (!(event.getRightClicked() instanceof Villager)) return;
	Villager villager = (Villager) event.getRightClicked();

	if (plugin.isShopkeeper(villager)) return; // shopkeeper interaction is handled elsewhere
	Log.debug("Interaction with Non-shopkeeper villager ..");

	if (villager.hasMetadata("NPC")) {
		// ignore any interaction with citizens2 NPCs
		Log.debug("  ignoring (probably citizens2) NPC");
		return;
	}

	if (Settings.disableOtherVillagers) {
		// don't allow trading with other villagers
		event.setCancelled(true);
		Log.debug("  trade prevented");
	}

	// only trigger hiring for main-hand events:
	if (!NMSManager.getProvider().isMainHandInteraction(event)) return;

	if (Settings.hireOtherVillagers) {
		Player player = event.getPlayer();
		// allow hiring of other villagers
		Log.debug("  possible hire ..");
		if (this.handleHireOtherVillager(player, villager)) {
			// hiring was successful -> prevent normal trading
			Log.debug("    ..success (normal trading prevented)");
			event.setCancelled(true);
		} else {
			// hiring was not successful -> no preventing of normal villager trading
			Log.debug("    ..failed");
		}
	}
}
 
Example 11
Source File: FreezeModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteractEvent(PlayerInteractEntityEvent event) {
    if (event.getHand().equals(EquipmentSlot.HAND) && event.getPlayer().hasPermission("cardinal.punish.freeze") && event.getRightClicked() instanceof Player) {
        ItemStack item = event.getPlayer().getInventory().getItem(event.getHand());
        if (item != null && item.getType() == Material.ICE
                && item.getItemMeta() != null && item.getItemMeta().getDisplayName() != null
                && item.getItemMeta().getDisplayName().equals(ChatColor.AQUA + ChatConstant.UI_FREEZE_ITEM.getMessage(event.getPlayer().getLocale()))) {
            event.setCancelled(true);
            togglePlayerFreeze((Player) event.getRightClicked(), event.getPlayer());
        }
    }
}
 
Example 12
Source File: EntityInspectorTool.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public  void onInteractEntity(PlayerInteractEntityEvent event, PlayerDetails details) {
	Player player = event.getPlayer();
	Entity entity = event.getRightClicked();
	if (EntityNBT.isValidType(entity.getType())) {
		EntityNBT entityNBT = EntityNBT.fromEntity(entity);
		player.sendMessage(ChatColor.YELLOW + "Information about " + EntityTypeMap.getName(entity.getType()) + "");
		for (NBTVariableContainer container : entityNBT.getAllVariables()) {
			player.sendMessage("" + ChatColor.LIGHT_PURPLE + ChatColor.ITALIC + container.getName() + ":");
			for (String name : container.getVariableNames()) {
				String value = container.getVariable(name).get();
				player.sendMessage("  " + ChatColor.AQUA + name + ": " + ChatColor.WHITE + (value != null ? value : ChatColor.ITALIC + "none"));
			}
		}
		player.sendMessage(ChatColor.YELLOW + "Extra information:");

		boolean extra = false;
		if (entityNBT.getEntityType() == EntityType.VILLAGER) {
			player.sendMessage("" + ChatColor.LIGHT_PURPLE + ChatColor.ITALIC + "Trades done:");
			int i = 1;
			for (VillagerOffersVariable.Offer offer : ((VillagerOffersVariable) entityNBT.getVariable("Offers")).getOffers()) {
				player.sendMessage("  " + ChatColor.AQUA + "trade " + i + ": " + ChatColor.WHITE + offer.uses);
				++i;
			}
			extra = true;
		}
		if (!extra) {
			player.sendMessage("none");
		}
		event.setCancelled(true);
	} else {
		player.sendMessage(ChatColor.RED + "Not a valid entity!");
	}
}
 
Example 13
Source File: VillagerListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onVillagerInteract(PlayerInteractEntityEvent event) {
    if (Main.isPlayerInGame(event.getPlayer())) {
        GamePlayer gPlayer = Main.getPlayerGameProfile(event.getPlayer());
        Game game = gPlayer.getGame();
        if (event.getRightClicked().getType().isAlive() && !gPlayer.isSpectator
                && gPlayer.getGame().getStatus() == GameStatus.RUNNING) {
            for (GameStore store : game.getGameStores()) {
                if (store.getEntity().equals(event.getRightClicked())) {
                    event.setCancelled(true);

                    BedwarsOpenShopEvent openShopEvent = new BedwarsOpenShopEvent(gPlayer.getGame(),
                            event.getPlayer(), store, event.getRightClicked());
                    Main.getInstance().getServer().getPluginManager().callEvent(openShopEvent);

                    if (openShopEvent.getResult() != Result.ALLOW) {
                        return;
                    }

                    Main.openStore(event.getPlayer(), store);
                    return;
                }
            }

        }
    }
}
 
Example 14
Source File: ListenerShortcutRightClick.java    From TrMenu with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void rightClick(PlayerInteractEntityEvent e) {
    Player p = e.getPlayer();
    if (e.getRightClicked() instanceof Player && Bukkit.getPlayer(e.getRightClicked().getUniqueId()) != null && Bukkit.getPlayer(e.getRightClicked().getUniqueId()).isOnline()) {
        e.setCancelled(TrMenuAPI.openByShortcut(p, (p.isSneaking() ? TrMenu.SETTINGS.getString("SHORTCUT-OPEN.SNEAKING-RIGHT-CLICK-PLAYER", null) : TrMenu.SETTINGS.getString("SHORTCUT-OPEN.RIGHT-CLICK-PLAYER", null)), e.getRightClicked().getName()));
    }
}
 
Example 15
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
void onEntityInteract(PlayerInteractEntityEvent event) {
	if (!(event.getRightClicked() instanceof LivingEntity)) return;
	LivingEntity shopEntity = (LivingEntity) event.getRightClicked();
	Player player = event.getPlayer();
	String playerName = player.getName();
	Log.debug("Player " + playerName + " is interacting with entity at " + shopEntity.getLocation());
	Shopkeeper shopkeeper = plugin.getShopkeeperByEntity(shopEntity); // also check for citizens npc shopkeepers

	if (event.isCancelled() && !Settings.bypassShopInteractionBlocking) {
		Log.debug("  Cancelled by another plugin");
	} else if (shopkeeper != null) {
		// only trigger shopkeeper interaction for main-hand events:
		if (NMSManager.getProvider().isMainHandInteraction(event)) {
			shopkeeper.onPlayerInteraction(player);
		}

		// if citizens npc: don't cancel the event, let Citizens perform other actions as appropriate
		if (shopkeeper.getShopObject().getObjectType() != DefaultShopObjectTypes.CITIZEN()) {
			// always cancel interactions with shopkeepers, to prevent any default behavior:
			event.setCancelled(true);

			// update inventory in case interaction would trigger feeding normally:
			player.updateInventory();
		}
	} else {
		Log.debug("  Non-shopkeeper");
	}
}
 
Example 16
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
	if (shouldHandleEvent(event)) {
		Tameable tameable = (Tameable) event.getRightClicked();
		AnimalTamer currentOwner = tameable.getOwner();
		if (currentOwner == null || currentOwner.getName() == null) {
			return;
		}
		// Has the player clicked on one of his own pets?
		Player player = event.getPlayer();
		boolean isOwner = player.getUniqueId().equals(currentOwner.getUniqueId());
		// Retrieve new owner from the map and delete corresponding entry.
		Player newOwner = plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(player);
		// Has the player requested to free one of his pets?
		boolean freePet = plugin.getFreeCommand().collectPendingFreeRequest(player);

		// Cannot change ownership or free pet if not owner and no bypass permission.
		if ((newOwner != null || freePet) && !isOwner && !player.hasPermission("petmaster.admin")) {
			player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang()
					.getString("not-owner", "You do not own this pet!").replace("PLAYER", player.getName()));
			return;
		}

		if (newOwner != null) {
			changeOwner(player, currentOwner, newOwner, tameable);
		} else if (freePet) {
			freePet(player, currentOwner, tameable);
		} else if ((displayToOwner || !isOwner) && player.hasPermission("petmaster.showowner")) {
			displayHologramAndMessage(player, currentOwner, tameable);
		}
	}
}
 
Example 17
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void OnPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {

	if (event.getRightClicked().getType().equals(EntityType.HORSE)) {
		if (!HorseModifier.isCivCraftHorse((LivingEntity)event.getRightClicked())) {
			CivMessage.sendError(event.getPlayer(), "Invalid horse! You can only get horses from stable structures.");
			event.setCancelled(true);
			event.getRightClicked().remove();
			return;
		}
	}

	ItemStack inHand = event.getPlayer().getItemInHand();
		if (inHand != null) {

			boolean denyBreeding = false;
			switch (event.getRightClicked().getType()) {
			case COW:
			case SHEEP:
			case MUSHROOM_COW:
				if (inHand.getType().equals(Material.WHEAT)) {
					denyBreeding = true;
				}
				break;
			case PIG:
				if (inHand.getType().equals(Material.CARROT_ITEM)) {
					denyBreeding = true;
				}
				break;
			case HORSE:
				if (inHand.getType().equals(Material.GOLDEN_APPLE) ||
						inHand.getType().equals(Material.GOLDEN_CARROT)) {
					CivMessage.sendError(event.getPlayer(), "You cannot breed horses, buy them from the stable.");
					event.setCancelled(true);
					return;
				}
				break;
			case CHICKEN:
				if (inHand.getType().equals(Material.SEEDS) ||
					inHand.getType().equals(Material.MELON_SEEDS) ||
					inHand.getType().equals(Material.PUMPKIN_SEEDS)) {
					denyBreeding = true;
				}
				break;
			default:
				break;
			}

			if (denyBreeding) {
				ChunkCoord coord = new ChunkCoord(event.getPlayer().getLocation());
				Pasture pasture = Pasture.pastureChunks.get(coord);

				if (pasture == null) {
					CivMessage.sendError(event.getPlayer(), "You cannot breed mobs in the wild, take them to a pasture.");
					event.setCancelled(true);
				} else {
						int loveTicks;
						NBTTagCompound tag = new NBTTagCompound();
						((CraftEntity)event.getRightClicked()).getHandle().c(tag);
						loveTicks = tag.getInt("InLove");

						if (loveTicks == 0) {	
							if(!pasture.processMobBreed(event.getPlayer(), event.getRightClicked().getType())) {
								event.setCancelled(true);
							}
						} else {
							event.setCancelled(true);
						}
				}

				return;			
			}
		}
	if (!(event.getRightClicked() instanceof ItemFrame) && !(event.getRightClicked() instanceof Painting)) {
		return;
	}

	coord.setFromLocation(event.getPlayer().getLocation());
	TownChunk tc = CivGlobal.getTownChunk(coord);
	if (tc == null) {
		return;
	}

	Resident resident = CivGlobal.getResident(event.getPlayer().getName());
	if (resident == null) {
		return;
	}

	if(!tc.perms.hasPermission(PlotPermissions.Type.INTERACT, resident)) {
		event.setCancelled(true);
		CivMessage.sendErrorNoRepeat(event.getPlayer(), "You do not have permission to interact with this painting/itemframe.");
	}

}
 
Example 18
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private void inGameInteractEntity(PlayerInteractEntityEvent iee, Game game, Player player) {

  if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
    if (iee.getPlayer().getItemInHand().getType().equals(Material.MONSTER_EGG)
        || iee.getPlayer().getItemInHand().getType().equals(Material.MONSTER_EGGS)
        || iee.getPlayer().getItemInHand().getType().equals(Material.DRAGON_EGG)) {
      iee.setCancelled(true);
      return;
    }
  } else {
    if (iee.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.MONSTER_EGG)
        || iee.getPlayer().getInventory().getItemInMainHand().getType()
        .equals(Material.MONSTER_EGGS)
        || iee.getPlayer().getInventory().getItemInMainHand().getType()
        .equals(Material.DRAGON_EGG)
        || iee.getPlayer().getInventory().getItemInOffHand().getType()
        .equals(Material.MONSTER_EGG)
        || iee.getPlayer().getInventory().getItemInOffHand().getType()
        .equals(Material.MONSTER_EGGS)
        || iee.getPlayer().getInventory().getItemInOffHand().getType()
        .equals(Material.DRAGON_EGG)) {
      iee.setCancelled(true);
      return;
    }
  }

  if (iee.getRightClicked() != null
      && !iee.getRightClicked().getType().equals(EntityType.VILLAGER)) {
    List<EntityType> preventClickTypes =
        Arrays.asList(EntityType.ITEM_FRAME, EntityType.ARMOR_STAND);

    if (preventClickTypes.contains(iee.getRightClicked().getType())) {
      iee.setCancelled(true);
    }

    return;
  }

  if (game.isSpectator(player)) {
    return;
  }

  if (!BedwarsRel.getInstance().getBooleanConfig("use-build-in-shop", true)) {
    return;
  }

  iee.setCancelled(true);

  BedwarsOpenShopEvent openShopEvent =
      new BedwarsOpenShopEvent(game, player, game.getItemShopCategories(), iee.getRightClicked());
  BedwarsRel.getInstance().getServer().getPluginManager().callEvent(openShopEvent);

  if (openShopEvent.isCancelled()) {
    return;
  }

  if (game.getPlayerSettings(player).useOldShop()) {
    MerchantCategory.openCategorySelection(player, game);
  } else {
    NewItemShop itemShop = game.getNewItemShop(player);
    if (itemShop == null) {
      itemShop = game.openNewItemShop(player);
    }

    itemShop.setCurrentCategory(null);
    itemShop.openCategoryInventory(player);
  }
}
 
Example 19
Source File: InteractEvent.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onInteract(PlayerInteractEntityEvent event) {
    Entity entity = event.getRightClicked();
    if(!(StackTools.hasValidData(entity))){
        return;
    }
    if(event.getHand() == EquipmentSlot.OFF_HAND){
        return;
    }
    if(event.isCancelled()){
        return;
    }

    int stackSize = StackTools.getSize(entity);
    if(entity instanceof Animals){
        Animals animals = (Animals) entity;
        if(sm.getCompat().checkFood(entity, event.getPlayer().getInventory().getItemInMainHand()) && animals.canBreed()){
            if(StackTools.hasSizeMoreThanOne(entity)) {
                if (sm.getCustomConfig().getBoolean("multiply.breed")) {
                    int breedSize = stackSize;
                    int handSize = event.getPlayer().getInventory().getItemInMainHand().getAmount();
                    if (handSize < breedSize) {
                        breedSize = event.getPlayer().getInventory().getItemInMainHand().getAmount();
                        event.getPlayer().getInventory().setItemInMainHand(null);
                    }

                    int childAmount = breedSize / 2;
                    Animals child = (Animals) sm.getTools().duplicate(entity);
                    StackTools.setSize(child, childAmount);
                    child.setBaby();

                    event.getPlayer().getInventory().getItemInMainHand().setAmount(handSize - breedSize);
                    animals.setBreed(false);
                } else if (sm.getCustomConfig().getBoolean("divide-on.breed")) {
                    Entity newEntity = sm.getTools().duplicate(entity);
                    StackTools.setSize(newEntity,stackSize - 1);
                    StackTools.makeSingle(entity);
                }
                return;
            }
        }
    }
    if(sm.getCustomConfig().getBoolean("divide-on.name")) {
        ItemStack handItem = event.getPlayer().getInventory().getItemInMainHand();
        if (handItem.getType() == Material.NAME_TAG && handItem.getItemMeta().hasDisplayName()) {
            if (stackSize > 1) {
                Entity dupe = sm.getTools().duplicate(entity);
                StackTools.setSize(dupe,stackSize - 1);
            }
            StackTools.removeSize(entity);
        }
    }
}
 
Example 20
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onItemFrameRotate(PlayerInteractEntityEvent event) {
    if (region.contains(event.getRightClicked().getLocation().toVector()) && event.getRightClicked() instanceof ItemFrame && filter.evaluate(event.getPlayer(), event.getRightClicked(), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
    }
}