本文整理匯總了Java中org.bukkit.event.player.PlayerInteractEvent.getHand方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInteractEvent.getHand方法的具體用法?Java PlayerInteractEvent.getHand怎麽用?Java PlayerInteractEvent.getHand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.event.player.PlayerInteractEvent
的用法示例。
在下文中一共展示了PlayerInteractEvent.getHand方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onWalkieTalkieInteract
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onWalkieTalkieInteract(PlayerInteractEvent e) {
if (e.getPlayer().getInventory().getItemInMainHand().getType() != Material.REDSTONE_COMPARATOR)
return;
if (e.getHand() == EquipmentSlot.OFF_HAND)
return;
WalkieTalkie wt = new WalkieTalkie(main,
main.getPlayerManager().getPlayer(e.getPlayer()).getCurrentWalkieTalkieFrequency());
// Left click to tune frequency.
if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
if (e.getPlayer().isSneaking()) {
wt.decreaseFrequency(e.getPlayer());
} else {
wt.increaseFrequency(e.getPlayer());
}
}
}
示例2: onPlayerInteract
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player p = event.getPlayer();
ItemStack item = event.getPlayer().getEquipment().getItemInMainHand();
if (event.getHand() == EquipmentSlot.HAND && item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
String name = item.getItemMeta().getDisplayName();
if (itemNameToIdentifierMap.containsKey(name)) {
String identifier = itemNameToIdentifierMap.get(name);
if (itemIdentifierToRunnableMap.containsKey(identifier)) {
PlayerDataRPG pd = plugin.getPD(p);
if (pd != null)
itemIdentifierToRunnableMap.get(identifier).run(event, p, pd);
event.setCancelled(true);
}
}
}
}
示例3: listener
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@Override
protected Listener listener(Consumer<Block> callback) {
return new Listener() {
@EventHandler
public void onClick(PlayerInteractEvent event) {
Player clicker = event.getPlayer();
EquipmentSlot hand = event.getHand();
Block block = event.getClickedBlock();
if (block != null && clicker.equals(player)
&& (!MCUtils.isOffHandSupport() || hand == EquipmentSlot.HAND)) {
clicker.sendMessage(MCUtils.colorize(messageFunc.apply(block)));
callback.accept(block);
event.setCancelled(true);
}
}
};
}
示例4: onClickEndPortalFrame
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onClickEndPortalFrame(PlayerInteractEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
Block clickedBlock = event.getClickedBlock();
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || world.getEnvironment() != Environment.THE_END
|| clickedBlock.getType() != Material.BEDROCK || event.getHand() != EquipmentSlot.HAND
|| (player.getInventory().getItemInMainHand() != null || player.getInventory().getItemInOffHand() != null)) return;
NMSAbstract nmsAbstract = plugin.getNMSAbstract();
DragonBattle dragonBattle = nmsAbstract.getEnderDragonBattleFromWorld(world);
Location portalLocation = dragonBattle.getEndPortalLocation();
if (event.getClickedBlock().getLocation().distanceSquared(portalLocation) > 36) return; // 5 blocks
EndWorldWrapper endWorld = plugin.getDEDManager().getWorldWrapper(world);
int secondsRemaining = endWorld.getTimeUntilRespawn();
if (secondsRemaining <= 0) return;
plugin.sendMessage(player, "Dragon will respawn in " + ChatColor.YELLOW + secondsRemaining);
}
示例5: onSpawn
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSpawn(PlayerInteractEvent e){
Player p = e.getPlayer();
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(e.getHand() != EquipmentSlot.HAND) return;
if (e.getItem() == null || !e.getItem().hasItemMeta() || !e.getItem().getItemMeta().hasDisplayName() || e.getItem().getType() != Material.MONSTER_EGG) return;
if (!ChatColor.stripColor(e.getItem().getItemMeta().getDisplayName()).contains("Spawn")) return;
if (!files.getConfig().getStringList("mundosPermitidos").contains(p.getLocation().getWorld().getName())) {
p.sendMessage(this.plugin.getPrefix() + ChatColor.RED + "No se puede usar en este mundo");
return;
}
int id = Integer.parseInt(e.getItem().getItemMeta().getLore().get(0));
String s = e.getItem().getItemMeta().getLore().get(1);
RegionManager m = WGBukkit.getPlugin().getRegionManager(p.getWorld());
if (m != null) {
m.getApplicableRegions(p.getLocation()).getRegions().forEach(re ->{
if (re != null && re.getOwners().contains(p.getUniqueId())) {
return;
}
});
}
SNMob mob = new SNMob(p);
if (!mob.isOwner(id)) {
p.sendMessage(SafariNet.getInstance().getPrefix() + ChatColor.RED + "No eres el dueño de este huevo");
return;
}
mob.spawnMob(id, s);
p.getInventory().getItemInMainHand().setAmount(-1);
}
}
示例6: onInteract
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onInteract(PlayerInteractEvent e){
Player p = e.getPlayer();
Weapon weapon;
if (e.getItem() == null || e.getHand() != EquipmentSlot.HAND) return;
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
if (e.getItem().getType() == Material.POTION) return;
if (e.getItem() == null || Weapon.getWeaponByItemStack(e.getItem()) == null || !Weapon.isWeapon(e.getItem())) return;
weapon = Weapon.getWeaponByItemStack(e.getItem());
if (weapon != null) e.setCancelled(true);
if (weapon == null) return;
weapon.shoot(p);
return;
}
if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK){
if (e.getItem() == null || Weapon.getWeaponByItemStack(e.getItem()) == null || !Weapon.isWeapon(e.getItem())) return;
weapon = Weapon.getWeaponByItemStack(e.getItem());
if (weapon != null) e.setCancelled(true);
if (weapon == null) return;
if (weapon.getId() == 0) return;
weapon.watch(p);
}
}
示例7: onInteractBusy
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onInteractBusy(PlayerInteractEvent event) {
if (event.getClickedBlock() == null)
return;
if (!inUse.contains(event.getClickedBlock().getLocation()))
return;
event.setCancelled(true);
if (event.getHand() == EquipmentSlot.HAND)
event.getPlayer().sendMessage(ChatColor.RED + "That generator is busy right now!");
}
示例8: onPlayerLeaverInteract
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onPlayerLeaverInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
Block clicked = e.getClickedBlock();
if (clicked == null)
return;
Block underneath = clicked.getRelative(BlockFace.DOWN);
Location underneathLoc = underneath.getLocation();
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getHand() == EquipmentSlot.OFF_HAND)
return;
if (clicked.getType() != Material.LEVER || underneath == null)
return;
String chunk = clicked.getLocation().getChunk().getX() + ";" + clicked.getLocation().getChunk().getZ();
if (underneath.getType() == Material.SPONGE && !underneath.isBlockPowered()) {
if (!main.getGeckManager().isGeckBuildCorrect(underneath)) {
p.sendMessage(ChatColor.RED + "You must build the GECK correctly!");
// Check if the geck is inside the powerables list
} else if (main.getGenListener().getPowerable().get(clicked.getWorld().getName()).getList(chunk)
.contains(underneathLoc)) {
main.getGeckObjectManager().addGeckLocation(underneathLoc);
main.getGeckObjectManager().getGeckObject(underneathLoc).setCorrect(true);
main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(true);
p.sendMessage(ChatColor.GREEN + "GECK Enabled!");
return;
}
} else if (main.getGeckObjectManager().getGeckObject(underneathLoc) != null && underneath.isBlockPowered()) {
main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(false);
main.getGeckObjectManager().removeGeckLocation(underneathLoc);
p.sendMessage(ChatColor.RED + "GECK Disabled!");
}
}
示例9: onSpawn
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSpawn(PlayerInteractEvent e){
Player p = e.getPlayer();
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(e.getHand() != EquipmentSlot.HAND) return;
if (e.getItem() == null || !e.getItem().hasItemMeta() || !e.getItem().getItemMeta().hasDisplayName() || e.getItem().getType() != Material.MONSTER_EGG) return;
if (!ChatColor.stripColor(e.getItem().getItemMeta().getDisplayName()).contains("Spawn")) return;
int id = Integer.parseInt(e.getItem().getItemMeta().getLore().get(0));
String s = e.getItem().getItemMeta().getLore().get(1);
boolean canCatch = true;
ApplicableRegionSet region = plugin.getWg().getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation());
for (ProtectedRegion r : region.getRegions()) if (!r.getOwners().contains(p.getName())) canCatch = false;
if (!canCatch) {
p.sendMessage(SafariNet.getInstance().getPrefix() + ChatColor.RED + "No puedes spawnear un mob en parcelas ajenas");
return;
}
SNMob mob = new SNMob(p);
if (!mob.isOwner(id)) {
p.sendMessage(SafariNet.getInstance().getPrefix() + ChatColor.RED + "No eres el dueño de este huevo");
return;
}
mob.spawnMob(id, s);
p.getInventory().getItemInMainHand().setAmount(-1);
}
}
示例10: onRuneUse
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onRuneUse(PlayerInteractEvent event) {
if(!(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
return;
}
if(event.getHand() == null || !event.getHand().equals(EquipmentSlot.HAND)) {
return;
}
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
if(item == null || item.getItemMeta() == null || !item.getType().equals(Material.ENCHANTED_BOOK)) {
return;
}
Player player = event.getPlayer();
Rune rune = plugin.getRuneManager().getRune(item.getItemMeta().getDisplayName().substring(2));
if(rune == null) {
return;
}
event.setCancelled(true);
if(plugin.getRuneManager().hasActiveRune(player)) {
player.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_RUNE_ALREADY_ACTIVE.toString());
return;
}
if(Cooldowns.getCooldown(player, "rune") > 0) {
player.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_RUNE_COOLDOWN.toString()
.replaceAll("%d", Convert.timeToString((int) (Cooldowns.getCooldown(player, "rune") / 1000))));
return;
}
plugin.getRuneManager().start(player, rune);
}
示例11: onBrewingClick
import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBrewingClick(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
ItemStack itemstack = event.getItem();
if ((itemstack == null) || (itemstack.getType() != Material.BLAZE_POWDER)) {
return;
}
itemstack = itemstack.clone();
Block clicked = event.getClickedBlock();
BlockState state = clicked.getState();
if (!(state instanceof BrewingStand)) {
return;
}
BrewingStand stand = (BrewingStand) state;
ItemStack existing = stand.getInventory().getFuel();
if (existing != null) {
existing = existing.clone();
}
PlayerInventory inventory = event.getPlayer().getInventory();
switch (event.getHand()) {
case HAND: {
inventory.setItemInMainHand(existing);
break;
}
case OFF_HAND: {
inventory.setItemInOffHand(existing);
break;
}
default: {
throw new IllegalArgumentException("Unexpected hand slot in interaction: " + event.getHand());
}
}
stand.getInventory().setFuel(itemstack);
event.setCancelled(true);
}