本文整理汇总了Java中org.bukkit.inventory.EquipmentSlot类的典型用法代码示例。如果您正苦于以下问题:Java EquipmentSlot类的具体用法?Java EquipmentSlot怎么用?Java EquipmentSlot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EquipmentSlot类属于org.bukkit.inventory包,在下文中一共展示了EquipmentSlot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onWalkieTalkieInteract
import org.bukkit.inventory.EquipmentSlot; //导入依赖的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.inventory.EquipmentSlot; //导入依赖的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: misfire
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
/**
* Computes chance that the gun misfires! Yikes.
*
* Misfire is based on when you last repaired the gun. A misfire has a chance of causing a gun to explode (handled in another function)
*
*
*
* @param entity the entity shooting the gun
* @param bulletType the type of bullet
* @param item the gunItem, could be modified by this.
* @param gunData the gunData
* @param hand the hand holding the gun.
*
* @return true if misfired, false otherwise.
*/
public boolean misfire(LivingEntity entity, Bullet bulletType, ItemStack item, Map<String, Object> gunData,
EquipmentSlot hand) {
if (entity == null || !enabled)
return true;
Integer health = (Integer) gunData.get("health"); // gunhealth!
double misfireChance = 1.0d - sigmoid((double) health, (double) this.middleRisk,0.5d, (double) this.riskSpread);
double random = Math.random();
AddGun.getPlugin().debug("Misfire computation: {0} health {1} misfireChance {2} random", health, misfireChance, random);
if (random < misfireChance) {
return true;
}
return false;
}
示例4: onInteract
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
Player p = e.getPlayer();
if(hasPermission(enchant_open, p))
{
Location loc = new Location(p.getWorld(), 10000.0D, 255.0D, 10000.0D);
//Can't be handled differently :(
Block im5 = loc.getBlock();
if(im5.getType() != Material.ENCHANTMENT_TABLE)
{
im5.setType(Material.ENCHANTMENT_TABLE);
}
p.openEnchanting(loc, true);
}
super.onInteract(e, es);
}
示例5: onInteract
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
if(es.equals(EquipmentSlot.HAND))
{
Player p = e.getPlayer();
ItemStack stack = es.equals(EquipmentSlot.HAND) ? p.getInventory().getItemInMainHand() : p.getInventory().getItemInOffHand();
ItemStack[] istack = loadInventory(getCompoundOfItemStack(stack), size);
CInventory inv = Bags2.bagGUI.createInventory(stack.getItemMeta().getDisplayName(), istack, size);
// inv.slot = p.getInventory().getHeldItemSlot();
// p.openInventory(inv.getInternalInventory());
inv.openInventory(p);
}
super.onInteract(e, es);
}
示例6: onInteract
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
ItemStack stack = es.equals(EquipmentSlot.HAND) ? e.getPlayer().getInventory().getItemInMainHand() : e.getPlayer().getInventory().getItemInOffHand();
if(stack.hasItemMeta() ? !stack.getItemMeta().getDisplayName().equals(Translation.get(name)) : false)
{
if(stack.getItemMeta().getDisplayName().startsWith(ChatColor.RESET.toString()))
{
ItemMeta im = stack.getItemMeta();
if(!im.getDisplayName().startsWith(ChatColor.ITALIC.toString()))
im.setDisplayName(ChatColor.RESET + Translation.get(name));
stack.setItemMeta(im);
if(es.equals(EquipmentSlot.HAND))
e.getPlayer().getInventory().setItemInMainHand(stack);
else
e.getPlayer().getInventory().setItemInOffHand(stack);
}
}
super.onInteract(e, es);
}
示例7: placeBlock
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
/**
* "simulate" a block place when you click on the side of a duct
*/
public static boolean placeBlock(Player p, Block b, Block placedAgainst, int id, byte data, EquipmentSlot es) {
if (!DuctUtils.canBuild(p, b, placedAgainst, es)) {
return false;
}
// check if there is already a duct at this position
Map<BlockLoc, Duct> ductMap = TransportPipes.instance.getDuctMap(b.getWorld());
if (ductMap != null) {
if (ductMap.containsKey(BlockLoc.convertBlockLoc(b.getLocation()))) {
return false;
}
}
if (!(b.getType() == Material.AIR || b.isLiquid())) {
return false;
}
b.setTypeIdAndData(id, data, true);
if (TransportPipes.instance.containerBlockUtils.isIdContainerBlock(id)) {
TransportPipes.instance.containerBlockUtils.updateDuctNeighborBlockSync(b, true);
}
return true;
}
示例8: listener
import org.bukkit.inventory.EquipmentSlot; //导入依赖的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);
}
}
};
}
示例9: init
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
public static void init(MCLibrary plugin) {
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
@SuppressWarnings("deprecation")
public void onInteract(PlayerInteractEvent event) {
if (MCUtils.isOffHandSupport() && event.getHand() != EquipmentSlot.HAND)
return;
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (block == null || !INFO_LISTENERS.contains(player))
return;
Location loc = block.getLocation();
CommandSenderWrapper wrapper = new CommandSenderWrapper(player);
wrapper.sendMessage("---------------------------------------------");
wrapper.sendMessage("&eworld: &f" + loc.getWorld().getName());
wrapper.sendMessage(String.format("&ex: &f%s (%s)", loc.getBlockX(), loc.getX()));
wrapper.sendMessage(String.format("&ey: &f%s (%s)", loc.getBlockY(), loc.getY()));
wrapper.sendMessage(String.format("&ez: &f%s (%s)", loc.getBlockZ(), loc.getZ()));
wrapper.sendMessage(String.format("&eblock: &f%s:%s (%s)", block.getTypeId(), block.getData(), block.getType().name()));
}
}, plugin);
}
示例10: onClickEndPortalFrame
import org.bukkit.inventory.EquipmentSlot; //导入依赖的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);
}
示例11: getEquipmentSlot
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
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;
}
示例12: onInteract
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
@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.");
}
}
}
}
示例13: canEdit
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
boolean canEdit(Player player, ArmorStand as){
ignoreNextInteract = true;
ArrayList<Event> events = new ArrayList<Event>();
events.add(new PlayerInteractEntityEvent(player, as, EquipmentSlot.HAND));
events.add(new PlayerInteractAtEntityEvent(player, as, as.getLocation().toVector(), EquipmentSlot.HAND));
//events.add(new PlayerArmorStandManipulateEvent(player, as, player.getEquipment().getItemInMainHand(), as.getItemInHand(), EquipmentSlot.HAND));
for(Event event : events){
if(!(event instanceof Cancellable)) continue;
try{
plugin.getServer().getPluginManager().callEvent(event);
} catch(IllegalStateException ise){
ise.printStackTrace();
ignoreNextInteract = false;
return false; //Something went wrong, don't allow edit just in case
}
if(((Cancellable)event).isCancelled()){
ignoreNextInteract = false;
return false;
}
}
ignoreNextInteract = false;
return true;
}
示例14: allowedByBlockPlaceEvent
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
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;
}
示例15: blockPlacePretend
import org.bukkit.inventory.EquipmentSlot; //导入依赖的package包/类
/**
* 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;
}