本文整理汇总了Java中org.bukkit.event.player.PlayerInteractEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInteractEvent.setCancelled方法的具体用法?Java PlayerInteractEvent.setCancelled怎么用?Java PlayerInteractEvent.setCancelled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.player.PlayerInteractEvent
的用法示例。
在下文中一共展示了PlayerInteractEvent.setCancelled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUseBackpack
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST)
public void onUseBackpack(PlayerInteractEvent event) {
ItemStack item = event.getItem();
if (!event.hasItem() || !ItemUtils.hasTag(item, ItemUtils.BACKPACK_TAG)) {
return;
}
Player player = event.getPlayer();
Action action = event.getAction();
if ((action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)
&& InventoryManager.isQuickSlot(player.getInventory().getHeldItemSlot())) {
BackpackManager.open(player, item);
}
event.setCancelled(true);
player.updateInventory();
}
示例2: onSpectatorInteract
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
public void onSpectatorInteract(PlayerInteractEvent event) {
Player p = event.getPlayer();
Gamer g = Gamer.get(p.getName());
if (!g.isInvisible())
return;
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.PHYSICAL) {
event.setCancelled(true);
return;
}
int cur = 0;
if (g.getVariable("spectating") != null)
cur = (Integer) g.getVariable("spectating");
int next = cur + 1;
if (next + 1 >= Game.getTributes().size())
next = 0;
g.setVariable("spectating", next);
Gamer t = Game.getTributes().get(next);
g.getPlayer().teleport(t.getPlayer().getLocation());
Chat.player(g.getPlayer(), "&2[SG] &eCurrently spectating " + g.getPrefix() + g.getName());
event.setCancelled(true);
}
示例3: onInteract
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerInteractEvent evt) {
if (!evt.getPlayer().equals(currentPainter))
return;
Block target = evt.getPlayer().getTargetBlock((Set<Material>) null, 50);
if (target.getZ() != ARENA_Z || target.getX() < MIN_X || target.getX() > MAX_X)
return; // Not clicking on the canvas.
if (target.getY() > MAX_Y && target.getY() <= MAX_Y + 5) { // Pick color.
penTime = 0;
currentColor = target.getData();
updateActionBar();
currentPainter.playSound(currentPainter.getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 0.75F, 1.75F);
} else if (evt.getAction() == Action.RIGHT_CLICK_AIR) { // Pen Tool
penTime = System.currentTimeMillis() + 200;
placeInk();
evt.setCancelled(true); // Prevent "cl
} else if (evt.getAction() == Action.LEFT_CLICK_AIR) { // Fill
playSound(Sound.ENTITY_BOBBER_SPLASH, 1.5F, 0.5F);
floodFill(target);
}
}
示例4: onClick
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
public void onClick(PlayerInteractEvent e) {
Action act = e.getAction();
if (!(act.equals(Action.RIGHT_CLICK_AIR) || act.equals(Action.RIGHT_CLICK_BLOCK)))
return;
ItemStack item = e.getItem();
if (item == null)
return;
if (!item.hasItemMeta())
return;
if (!item.getItemMeta().hasDisplayName())
return;
if (!item.getItemMeta().getDisplayName().contains(ConfigManager.getInstance().getBackpackName()))
return;
Player p = e.getPlayer();
String name = p.getName();
if (BackpackCooldown.getInstance().isReady(name, 500)) {
BackpackCooldown.getInstance().put(name);
} else {
e.setCancelled(true);
p.closeInventory();
p.sendMessage(Messages.getMessages().getNoQuickOpen().replace("&", "§"));
}
}
示例5: onPlayerInteract
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
// The player didn't click an enchantment table, Creative players will instantly destroy.
Player player = event.getPlayer();
if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {
// The player didn't click with an enchanted book.
ItemStack stack = event.getItem();
if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
ItemMeta meta = stack.getItemMeta();
if (meta instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
enchantmentStorageMeta.removeStoredEnchant(enchantment);
}
event.setCancelled(true);
player.setItemInHand(EMPTY_BOOK);
player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
}
}
}
}
}
示例6: handleUse
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
private void handleUse(Event event, BlockState blockState, MatchPlayer player) {
if(!player.canInteract()) return;
PlayerBlockEventQuery query = new PlayerBlockEventQuery(player, event, blockState);
for(EventRule rule : this.ruleContext.get(EventRuleScope.USE)) {
if(rule.region().contains(blockState)) {
if(processQuery(rule, query)) {
if(query.getEvent() instanceof PlayerInteractEvent && ((PlayerInteractEvent) query.getEvent()).isCancelled()) {
PlayerInteractEvent pie = (PlayerInteractEvent) query.getEvent();
pie.setCancelled(false);
pie.setUseItemInHand(Event.Result.ALLOW);
pie.setUseInteractedBlock(Event.Result.DENY);
if(rule.message() != null) {
player.sendWarning(rule.message(), false);
}
}
if(this.useRegionPriority) {
break;
}
}
}
}
}
示例7: onPlayerInteractWhenNotLoaded
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteractWhenNotLoaded(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (InventoryManager.isAllowedWorld(player.getWorld()) && !InventoryManager.playerIsLoaded(player)) {
PlayerUtils.sendMessage(player, RPGInventory.getLanguage().getMessage("error.rp.denied"));
event.setCancelled(true);
}
}
示例8: onInteract
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
public void onInteract(final PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) return;
ItemStack item = event.getItem();
if (item instanceof PlayerheadItemStack) {
event.setCancelled(true);
Player player = event.getPlayer();
//Use the item
if (item.getAmount() > 1) item.setAmount(item.getAmount() - 1);
else player.getInventory().remove(item);
MainConfiguration config = UHC.getInstance().getMainConfig();
//Give effects & crap
PlayerheadItemStack playerhead = (PlayerheadItemStack) item;
boolean golden = playerhead.isGolden();
player.sendMessage(colour("&aYou ate " + playerhead.getFrom() + "'s playerhead!"));
int regenDuration = golden ? config.getGoldenHeadRegenerationDuration() : config.getHeadRegenerationDuration();
int regenAmpf = golden ? config.getGoldenHeadRegenerationAmplifier() : config.getHeadRegenerationAmplifier();
int absorpDuration = golden ? config.getGoldenHeadAbsorptionDuration() : config.getHeadAbsorptionDuration();
int absorpAmpf = golden ? config.getGoldenHeadAbsorptionAmplifier() : config.getHeadAbsorptionAmplifier();
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, regenDuration, regenAmpf, false, true));
player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, absorpDuration, absorpAmpf, false, true));
}
}
示例9: onPlayerInteract
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e)
{
User user = MWAPI.getUserHandler().findById(e.getPlayer().getUniqueId());
if (user.getGame() != null)
{
Game game = user.getGame();
if (game.getState() == GameState.LOBBY && game.isPlaying(user))
{
e.setCancelled(true);
e.getPlayer().updateInventory();
if (e.getPlayer().getItemInHand().getType().equals(Material.CHEST))
{
e.getPlayer().sendMessage(ChatColor.RED + "Coming Soon.");
}
else if (e.getPlayer().getItemInHand().getType().equals(Material.WOOL))
{
e.getPlayer().sendMessage(ChatColor.RED + "Coming Soon.");
}
else if (e.getPlayer().getItemInHand().getType().equals(Material.BED))
{
boolean success = game.leave(user);
if (success)
{
user.getPlayer().sendMessage(ChatColor.GOLD + "Successfully left game " + game.getId() + ".");
}
else
{
user.getPlayer().sendMessage(ChatColor.RED + "Error while leaving game " + game.getId() + ".");
}
}
}
}
}
示例10: onInteract
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
public void onInteract(PlayerInteractEvent e) {
final TOAUser u = TOA.getPlayer(e.getPlayer());
if (e.getItem() != null) {
Material m = e.getItem().getType();
if (m == Material.WRITTEN_BOOK || m == Material.BOW || m == Material.SHEARS || m == Material.DIAMOND_SWORD) return;
Ability.useAbility(u, e.getItem().getType());
e.setCancelled(true);
}
if (!u.isOnRank(PACmd.Grupo.Builder)) {
if (e.getClickedBlock() != null) {
if (e.getClickedBlock().getType().equals(Material.TRAP_DOOR) || e.getClickedBlock().getType().equals(Material.IRON_TRAPDOOR)
|| e.getClickedBlock().getType().equals(Material.FENCE_GATE) || e.getClickedBlock().getType().equals(Material.FIRE)
|| e.getClickedBlock().getType().equals(Material.CAULDRON) || e.getClickedBlock().getRelative(BlockFace.UP).getType().equals(Material.FIRE)
|| e.getClickedBlock().getType() == Material.CHEST || e.getClickedBlock().getType() == Material.TRAPPED_CHEST
|| e.getClickedBlock().getType() == Material.DROPPER || e.getClickedBlock().getType() == Material.DISPENSER
|| e.getClickedBlock().getType() == Material.BED_BLOCK || e.getClickedBlock().getType() == Material.BED
|| e.getClickedBlock().getType() == Material.WORKBENCH || e.getClickedBlock().getType() == Material.BREWING_STAND
|| e.getClickedBlock().getType() == Material.ANVIL || e.getClickedBlock().getType() == Material.DARK_OAK_FENCE_GATE
|| e.getClickedBlock().getType() == Material.SPRUCE_FENCE_GATE || e.getClickedBlock().getType() == Material.FURNACE
|| e.getClickedBlock().getType() == Material.BURNING_FURNACE || e.getClickedBlock().getType() == Material.HOPPER
|| e.getClickedBlock().getType() == Material.STONE_BUTTON || e.getClickedBlock().getType() == Material.WOOD_BUTTON) {
e.setCancelled(true);
}
}
}
}
示例11: onFoodEat
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void onFoodEat(PlayerInteractEvent event) {
if(!(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
return;
}
if(!event.getPlayer().isSneaking() || event.getPlayer().getInventory().getItemInMainHand() == null) {
return;
}
Player player = event.getPlayer();
List<Integer> ids = GodFoodFile.getFoodId(player.getInventory().getItemInMainHand().getTypeId());
for(int id : ids) {
byte data = (byte)GodFoodFile.getData(id);
if(player.getInventory().getItemInMainHand().getData().getData() != data || id == 0)
continue;
if(player.getInventory().getItemInMainHand().getAmount() > GodFoodFile.getAmount(id)) {
ItemStack item = player.getInventory().getItemInMainHand();
item.setAmount(item.getAmount() - GodFoodFile.getAmount(id));
player.setItemInHand(item);
} else if(player.getInventory().getItemInMainHand().getAmount() == GodFoodFile.getAmount(id)) {
player.setItemInHand(new ItemStack(Material.AIR));
} else {
return;
}
event.setCancelled(true);
addPotionEffects(player, id);
player.sendMessage(Lang.HEADERS_FOG.toString() + "You used "
+ ChatColor.RED + GodFoodFile.getName(id) + ChatColor.GRAY + "!");
}
}
示例12: onAnvilOrEnchantInteract
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
public void onAnvilOrEnchantInteract(PlayerInteractEvent event) {
if (event.getClickedBlock() != null) {
if (event.getPlayer().getGameMode() == GameMode.CREATIVE && (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK))
return;
Material type = event.getClickedBlock().getType();
for (Material m : RESTRICTED_TYPES) {
if (m == type) {
event.setCancelled(true);
break;
}
}
}
}
示例13: anvilStuff
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void anvilStuff(PlayerInteractEvent e){
if(e.getClickedBlock() == null)return;
if(e.getClickedBlock().getType().equals(Material.ANVIL)){
e.setCancelled(true);
Player p = e.getPlayer();
String uuid = p.getUniqueId().toString();
long tokens = getTokens(uuid);
if(p.getItemInHand().getType() == Material.AIR ||
p.getItemInHand().getType() == Material.GOLDEN_APPLE ||
p.getItemInHand().getType() == Material.ARROW ||
p.getItemInHand().getType() == Material.POTION){
p.sendMessage(tag + ChatColor.RED + "You can\'t repair that!");
}else{
if(tokens < 1){
p.sendMessage(tag + ChatColor.RED + "You need at least 1 token to repair things!!");
}else{
if(p.getItemInHand().getDurability() > 0){
p.getItemInHand().setDurability((short) 0);
setTokens(uuid, getTokens(uuid)-1);
p.sendMessage(tag + ChatColor.BLUE + "Your item has been repaired");
}else{
p.sendMessage(tag + ChatColor.RED + "This item isn\'t broken");
}
}
}
}
}
示例14: InteractCheck
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
@SuppressWarnings("deprecation")
public void InteractCheck(PlayerInteractEvent event) {
if (ConfigPatch.noInfItem) {
Player player = event.getPlayer();
if (event.getItem() != null) {
if (event.getItem().getAmount() <= 0) {
event.setCancelled(true);
player.setItemInHand(null);
AzureAPI.log(player, ConfigPatch.AntiInfItemClickcWarnMessage);
}
}
}
}
示例15: cloneCraftingWindow
import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void cloneCraftingWindow(final PlayerInteractEvent event) {
if(!AntiGrief.CraftProtect.enabled()) {
return;
}
if(!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) {
Block block = event.getClickedBlock();
if(block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) {
// create the window ourself
event.setCancelled(true);
event.getPlayer().openWorkbench(null, true); // doesn't check reachable
}
}
}