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

The following examples show how to use org.bukkit.event.player.PlayerInteractEntityEvent#setCancelled() . 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: TNTSheepListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onTNTSheepInteractOtherUser(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gamePlayer = Main.getPlayerGameProfile(player);
        Game game = gamePlayer.getGame();

        Entity rightClicked = event.getRightClicked();
        Entity vehicle = rightClicked.getVehicle();
        List<SpecialItem> sheeps = game.getActivedSpecialItems(TNTSheep.class);
        for (SpecialItem item : sheeps) {
            if (item instanceof TNTSheep) {
                TNTSheep sheep = (TNTSheep) item;
                if (sheep.getEntity().equals(rightClicked) || sheep.getEntity().equals(vehicle)) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
 
Example 2
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInteractEvent(PlayerInteractEntityEvent e) {
    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is PlayerInteractEntityEvent");

    Player p = e.getPlayer();
    if (p == null) {
        return;
    }
    Location l = e.getRightClicked().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    Entity et = e.getRightClicked();
    if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem || (et instanceof WaterMob && !r.canFish(p)))) {
        if (et instanceof Tameable) {
            Tameable tam = (Tameable) et;
            if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())) {
                return;
            }
        }
        e.setCancelled(true);
        RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantinteract");
    }
}
 
Example 3
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 6 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onPlayerInteractItemFrame(PlayerInteractEntityEvent ev) {
    if (!(ev.getRightClicked() instanceof ItemFrame)) return;
    ItemFrame f = (ItemFrame) ev.getRightClicked();
    if (f.getItem() == null || f.getItem().getType() == Material.AIR) return;
    ExhibitionFrame fr = ExhibitionFrame.fromItemFrame(f);
    if (fr.isSet()) {
        new Message(I18n.format("user.exhibition.looking_at")).append(fr.getItemInFrame()).send(ev.getPlayer());
        ev.getPlayer().sendMessage(I18n.format("user.exhibition.provided_by", fr.getOwnerName()));
        for (String line : fr.getDescriptions()) {
            ev.getPlayer().sendMessage(line);
        }
        ev.setCancelled(true);
        if (fr.hasItem() && fr.getItemInFrame().getType() == Material.WRITTEN_BOOK) {
            ev.getPlayer().openBook(fr.getItemInFrame());
        }
    }
}
 
Example 4
Source File: TNTSheepListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onTNTSheepInteractOtherUser(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gamePlayer = Main.getPlayerGameProfile(player);
        Game game = gamePlayer.getGame();

        Entity rightClicked = event.getRightClicked();
        Entity vehicle = rightClicked.getVehicle();
        List<SpecialItem> sheeps = game.getActivedSpecialItems(TNTSheep.class);
        for (SpecialItem item : sheeps) {
            if (item instanceof TNTSheep) {
                TNTSheep sheep = (TNTSheep) item;
                if (sheep.getEntity().equals(rightClicked) || sheep.getEntity().equals(vehicle)) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
 
Example 5
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 6
Source File: PlayerInteractListener.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    try {
        final Player player = event.getPlayer();
        final User user = User.getUser(player);
        final Entity rightClicked = event.getRightClicked();
        final Location location = rightClicked.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        if (island.getPermissions(user).interact) return;

        event.setCancelled(true);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 7
Source File: EntityRemoverTool.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 (entity.getType() != EntityType.PLAYER) {
		event.getRightClicked().remove();
		event.setCancelled(true);
	} else {
		player.sendMessage(ChatColor.RED + "You cannot remove players!");
	}
}
 
Example 8
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 9
Source File: MobSelector.java    From CloudNet with Apache License 2.0 5 votes vote down vote up
@EventHandler
public void handleRightClick(PlayerInteractEntityEvent e) {
    MobImpl mobImpl = CollectionWrapper.filter(mobs.values(), new Acceptable<MobImpl>() {
        @Override
        public boolean isAccepted(MobImpl value) {
            return value.getEntity().getUniqueId().equals(e.getRightClicked().getUniqueId());
        }
    });

    if (mobImpl != null) {
        e.setCancelled(true);
        if (!CloudAPI.getInstance().getServerGroupData(mobImpl.getMob().getTargetGroup()).isMaintenance()) {
            if (mobImpl.getMob().getAutoJoin() != null && mobImpl.getMob().getAutoJoin()) {
                ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
                byteArrayDataOutput.writeUTF("Connect");

                List<ServerInfo> serverInfos = getServers(mobImpl.getMob().getTargetGroup());

                for (ServerInfo serverInfo : serverInfos) {
                    if (serverInfo.getOnlineCount() < serverInfo.getMaxPlayers() && serverInfo.getServerState()
                                                                                              .equals(ServerState.LOBBY)) {
                        byteArrayDataOutput.writeUTF(serverInfo.getServiceId().getServerId());
                        e.getPlayer().sendPluginMessage(CloudServer.getInstance().getPlugin(),
                                                        "BungeeCord",
                                                        byteArrayDataOutput.toByteArray());
                        return;
                    }
                }
            } else {
                e.getPlayer().openInventory(mobImpl.getInventory());
            }
        } else {
            e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',
                                                                             CloudAPI.getInstance()
                                                                                     .getCloudNetwork()
                                                                                     .getMessages()
                                                                                     .getString("mob-selector-maintenance-message")));
        }
    }
}
 
Example 10
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    if (testObserver(event.getPlayer())) {
        if (event.getRightClicked() instanceof Player && !event.getPlayer().isSneaking()){
            if (event.getHand().equals(EquipmentSlot.HAND)) openInventory(event.getPlayer(), (Player) event.getRightClicked(), false);
        } else if (event.getRightClicked() instanceof ItemFrame) {
            event.setCancelled(true);
        }
    }
}
 
Example 11
Source File: ListenerEntities.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority= EventPriority.HIGH, ignoreCancelled=true)
public void onInteract(PlayerInteractEntityEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("prevent-entity-interaction")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.no-entity-interaction");
    this.plugin.sendMessage(player, message);
}
 
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: 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 14
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 15
Source File: EntityInteractObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onRightClick(PlayerInteractEntityEvent e) {
    boolean success = onInteract(e.getPlayer(), e.getRightClicked());
    if (success && cancel) {
        e.setCancelled(true);
    }
}
 
Example 16
Source File: MenuConvIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void playerInteractEntityEvent(PlayerInteractEntityEvent event) {
    if (event.getPlayer() != player) {
        return;
    }

    event.setCancelled(true);

    if (debounce) {
        return;
    }

    if (controls.containsKey(CONTROL.LEFT_CLICK)) {
        switch (controls.get(CONTROL.LEFT_CLICK)) {
            case CANCEL:
                if (!conv.isMovementBlock()) {
                    conv.endConversation();
                }
                debounce = true;
                break;
            case SELECT:
                conv.passPlayerAnswer(selectedOption + 1);
                debounce = true;
                break;
        case MOVE:
            break;
        default:
            break;
        }
    }
}
 
Example 17
Source File: NoRightClick.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
	event.setCancelled(true);
}
 
Example 18
Source File: Powergloves.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean effect(Event event, final Player player) {
	if(event instanceof PlayerInteractEntityEvent) {
		PlayerInteractEntityEvent e = (PlayerInteractEntityEvent) event;
		e.setCancelled(true);
		final Entity clicked = e.getRightClicked();
		if(!player.hasMetadata("ce." + getOriginalName()))
			if(!clicked.getType().equals(EntityType.PAINTING) && !clicked.getType().equals(EntityType.ITEM_FRAME) && clicked.getPassenger() != player && player.getPassenger() == null) {
				player.setMetadata("ce." + getOriginalName(), new FixedMetadataValue(main, false));

				player.setPassenger(clicked);

				player.getWorld().playEffect(player.getLocation(), Effect.ZOMBIE_CHEW_IRON_DOOR, 10);

				new BukkitRunnable() {

					@Override
					public void run() {
						player.getWorld().playEffect(player.getLocation(), Effect.CLICK2, 10);
						player.setMetadata("ce." + getOriginalName(), new FixedMetadataValue(main, true));
						this.cancel();
					}
				}.runTaskLater(main, ThrowDelayAfterGrab);

				new BukkitRunnable() {

					int			GrabTime	= MaxGrabtime;
					ItemStack	current		= player.getItemInHand();

					@Override
					public void run() {
						if(current.equals(player.getItemInHand())) {
							current = player.getItemInHand();
						if(GrabTime > 0) {
							if(!player.hasMetadata("ce." + getOriginalName())) {
								this.cancel();
							}
							GrabTime--;
						} else if(GrabTime <= 0) {
							if(player.hasMetadata("ce." + getOriginalName())) {
								player.getWorld().playEffect(player.getLocation(), Effect.CLICK1, 10);
								player.removeMetadata("ce." + getOriginalName(), main);
								generateCooldown(player, getCooldown());
							}
							clicked.leaveVehicle();
							this.cancel();
						}
					  } else {
						  player.removeMetadata("ce." + getOriginalName(), main);
						  generateCooldown(player, getCooldown());
						  this.cancel();
					  }
					}
				}.runTaskTimer(main, 0l, 10l);
			}
	} else if(event instanceof PlayerInteractEvent) {
		if(player.hasMetadata("ce." + getOriginalName()) && player.getMetadata("ce." + getOriginalName()).get(0).asBoolean())
				if(player.getPassenger() != null) {
					Entity passenger = player.getPassenger();
					player.getPassenger().leaveVehicle();
					passenger.setVelocity(player.getLocation().getDirection().multiply(ThrowSpeedMultiplier));
					player.getWorld().playEffect(player.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
					player.removeMetadata("ce." + getOriginalName(), main);
					return true;
				}
	}
	return false;
}
 
Example 19
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 20
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    Location location = BukkitUtil.adapt(event.getRightClicked().getLocation());
    if (manager.isPlotWorld(location)) {
        //Citizens Support
        if (event.getRightClicked().hasMetadata("NPC") && event.getRightClicked().getMetadata("NPC").get(0).asBoolean()) {
            return;
        }

        Plot plot = manager.getPlot(location);

        if (plot == null) {
            if (!event.getPlayer().hasPermission(PermissionNames.ADMIN_BUILDANYWHERE)) {
                event.getPlayer().sendMessage(api.C("CannotBuild"));
                event.setCancelled(true);
            }
        } else {
            if (plot.getOwnerId().equals(event.getPlayer().getUniqueId())) {
                return;
            }
            if (!event.getPlayer().hasPermission(PermissionNames.ADMIN_BUILDANYWHERE)) {
                Optional<Plot.AccessLevel> member = plot.isMember(event.getPlayer().getUniqueId());
                if (plot.getOwnerId().equals(event.getPlayer().getUniqueId())) {
                    return;
                }
                if (member.isPresent()) {
                    if (member.get().equals(Plot.AccessLevel.TRUSTED) && !api.getServerBridge().getOfflinePlayer(plot.getOwnerId()).isOnline()) {
                        event.getPlayer().sendMessage(api.C("CannotBuild"));
                        event.setCancelled(true);
                    } else if (api.isPlotLocked(plot.getId())) {
                        event.getPlayer().sendMessage(api.C("PlotLocked"));
                        event.setCancelled(true);
                    }
                } else {
                    event.getPlayer().sendMessage(api.C("CannotBuild"));
                    event.setCancelled(true);
                }
            }
        }
    }
}