本文整理汇总了Java中org.bukkit.inventory.EquipmentSlot.HAND属性的典型用法代码示例。如果您正苦于以下问题:Java EquipmentSlot.HAND属性的具体用法?Java EquipmentSlot.HAND怎么用?Java EquipmentSlot.HAND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bukkit.inventory.EquipmentSlot
的用法示例。
在下文中一共展示了EquipmentSlot.HAND属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerInteract
@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);
}
}
}
}
示例2: listener
@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);
}
}
};
}
示例3: onClickEndPortalFrame
@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);
}
示例4: getEquipmentSlot
private static EquipmentSlot getEquipmentSlot(String slotName) {
if (!slotName.startsWith("slot.")) {
slotName = "slot." + slotName;
}
EquipmentSlot equipmentSlot = null;
String[] path = slotName.split("\\.");
if (path.length == 3) {
if (path[1].equalsIgnoreCase("armor")) {
equipmentSlot = EquipmentSlot.valueOf(Strings.getTechnicalName(path[2]));
} else if (path[1].equalsIgnoreCase("weapon")) {
if (path[2].equalsIgnoreCase("mainhand")) {
equipmentSlot = EquipmentSlot.HAND;
}
if (path[2].equalsIgnoreCase("offhand")) {
equipmentSlot = EquipmentSlot.OFF_HAND;
}
}
}
return equipmentSlot;
}
示例5: onInteract
@EventHandler
public void onInteract(PlayerInteractEvent e) {
if (e.getAction().toString().charAt(0) == 'R') {
Player p = e.getPlayer();
ItemStack i = e.getItem();
if (i == null)
return;
Hand hand = e.getHand() == EquipmentSlot.HAND ? Hand.MAIN : Hand.OFF;
List<String> lore = i.getItemMeta().getLore();
if (lore != null && lore.size() > 0) {
String id = lore.get(0).replace("�", "");
MysteryBag bag = instance.cheezBags.get(id);
if (bag != null) {
e.setCancelled(true);
if (p.hasPermission("mysterybags.open"))
bag.open(e.getPlayer(), hand);
else
p.sendMessage(MysteryBags.PREFIX + "�7You do not have permission to open that.");
}
}
}
}
示例6: allowedByBlockPlaceEvent
private boolean allowedByBlockPlaceEvent(Block placedBlock, BlockState replacedBlockState, Block placedAgainst,
Player player) {
Material originalMaterial = placedBlock.getType();
BlockPlaceEvent placeEvent = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst,
player.getInventory().getItemInMainHand(), player, true, EquipmentSlot.HAND);
Bukkit.getPluginManager().callEvent(placeEvent);
Material placedMaterial = placeEvent.getBlockPlaced().getType();
if (placeEvent.isCancelled() || !placedMaterial.equals(originalMaterial)) {
// We consider the event cancelled too when the placed block was
// changed
return false;
}
return true;
}
示例7: blockPlacePretend
/**
* Function for a moving machina to test whether it's allowed to move to a
* new location by protection plugins. Returns true if the player could
* build (and break) the new block.
*
* This function will fire a blockplace event, collect the cancelled result
* at the highest possible priority, then cancel its own event to prevent it
* from being logged by any monitoring plugins.
*
* @param target
* The target location to place at
* @param typeId
* The typeId of the block to place
* @param placedAgainst
* The block that it will be placed against
* @param player
* The player to simulate for
* @return True if the player may place a block at the location
*/
@SuppressWarnings("deprecation")
public static boolean blockPlacePretend(BlockLocation target, int typeId, BlockLocation placedAgainst, Player player) {
Block placedBlock = target.getBlock();
BlockState replacedBlockState = placedBlock.getState();
int oldType = replacedBlockState.getTypeId();
byte oldData = replacedBlockState.getRawData();
// Set the new state without physics.
placedBlock.setTypeIdAndData(typeId, (byte) 0, false);
pretendEvent = new ArtificialBlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst.getBlock(), new ItemStack(Material.AIR), player, true, EquipmentSlot.HAND);
pretendEventCancelled = true;
MachinaCore.pluginManager.callEvent(pretendEvent);
// Revert to the old state without physics.
placedBlock.setTypeIdAndData(oldType, oldData, false);
return !pretendEventCancelled;
}
示例8: onItemFrameClick
@SuppressWarnings("deprecation")
@EventHandler
public void onItemFrameClick(PlayerInteractEntityEvent event) {
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
return;
}
// this prevents the journal from being placed inside of item frame
if (event.getRightClicked() instanceof ItemFrame) {
ItemStack item = null;
try {
item = (event.getHand() == EquipmentSlot.HAND) ? event.getPlayer().getInventory().getItemInMainHand() : event.getPlayer().getInventory().getItemInOffHand();
} catch (LinkageError e) {
item = event.getPlayer().getItemInHand();
}
String playerID = PlayerConverter.getID(event.getPlayer());
if (Journal.isJournal(playerID, item) || Utils.isQuestItem(item)) {
event.setCancelled(true);
}
}
}
示例9: callBlockPlaceEvent
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, EnumHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
CraftWorld craftWorld = world.getWorld();
CraftServer craftServer = world.getServer();
Player player = (Player) who.getBukkitEntity();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
Block placedBlock = replacedBlockState.getBlock();
boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());
org.bukkit.inventory.ItemStack item;
EquipmentSlot equipmentSlot;
if (hand == EnumHand.MAIN_HAND) {
item = player.getInventory().getItemInMainHand();
equipmentSlot = EquipmentSlot.HAND;
} else {
item = player.getInventory().getItemInOffHand();
equipmentSlot = EquipmentSlot.OFF_HAND;
}
BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild, equipmentSlot);
craftServer.getPluginManager().callEvent(event);
return event;
}
示例10: onPlayerInteract
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
try {
if (e.getHand() != EquipmentSlot.HAND)
return;
} catch (Error ignored) {
}
if (e.getAction() != Action.PHYSICAL)
onClick(e); // this method cancels the event by himself
}
示例11: onInteract
@EventHandler
public void onInteract(PlayerInteractEvent e){
Player p = e.getPlayer();
Block b;
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getHand() == EquipmentSlot.HAND){
b = e.getClickedBlock();
if (plugin.getCasinos().contains(b.getLocation())){
e.setCancelled(true);
FichasMenu.openInventory(p);
}
}
}
示例12: onSpawn
@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);
}
}
示例13: onInteract
@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);
}
}
示例14: onInteractBusy
@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!");
}
示例15: onSpawn
@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);
}
}