当前位置: 首页>>代码示例>>Java>>正文


Java Player.getGameMode方法代码示例

本文整理汇总了Java中org.bukkit.entity.Player.getGameMode方法的典型用法代码示例。如果您正苦于以下问题:Java Player.getGameMode方法的具体用法?Java Player.getGameMode怎么用?Java Player.getGameMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.entity.Player的用法示例。


在下文中一共展示了Player.getGameMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPlayerInteract

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;

    Player player = event.getPlayer();
    if (player.getGameMode() == GameMode.CREATIVE && player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {
        return;
    }

    if (plugin.getEotwHandler().isEndOfTheWorld()) {
        return;
    }

    Block block = event.getClickedBlock();
    if (!this.isSubclaimable(block)) {
        return;
    }

    if (!this.checkSubclaimIntegrity(player, block)) {
        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You do not have access to this subclaimed " + block.getType().toString() + '.');
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:25,代码来源:SignSubclaimListener.java

示例2: onBlockBreak

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event)
{
  Block block = event.getBlock();
  if (isEventSign(block))
  {
    BlockState state = block.getState();
    Sign sign = (Sign)state;
    ItemStack stack = new ItemStack(Material.SIGN, 1);
    ItemMeta meta = stack.getItemMeta();
    meta.setDisplayName(EVENT_SIGN_ITEM_NAME);
    meta.setLore(Arrays.asList(sign.getLines()));
    stack.setItemMeta(meta);
    
    Player player = event.getPlayer();
    World world = player.getWorld();
    Location blockLocation = block.getLocation();
    if ((player.getGameMode() != GameMode.CREATIVE) && (world.isGameRule("doTileDrops"))) {
      world.dropItemNaturally(blockLocation, stack);
    }
    event.setCancelled(true);
    block.setType(Material.AIR);
    state.update();
  }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:26,代码来源:EventSignListener.java

示例3: onConsumeCake

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsumeCake(PlayerInteractEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.hasBlock() && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
	{
		Block cake = event.getClickedBlock();
		if(cake.getType().equals(Material.CAKE_BLOCK))
		{
			if(player.getFoodLevel() < 20 && (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE))
			{
				addStats(player, carbon, 171);
				addStats(player, protein, 114);
				addStats(player, salts, 3);
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:20,代码来源:FoodDiversityConsume.java

示例4: breakBlock

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static void breakBlock(Player player, Block block) {
    if (player.getGameMode() == GameMode.CREATIVE)
        return;

    PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player);
    if (playerBlockTracking.isBlock(block)) {
        playerBlockTracking.decrementHackingIndicator(2);
    }
}
 
开发者ID:SamaGames,项目名称:AntiCheat,代码行数:10,代码来源:BlockHitManager.java

示例5: onBlockPlaceCreative

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPlaceCreative(BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getGameMode() == GameMode.CREATIVE && !player.hasPermission("base.command.gamemode")) {
        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You are not allowed to be in gamemode! Setting you to default gamemode!");
        player.setGameMode(GameMode.SURVIVAL);
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:10,代码来源:CreativeClickListener.java

示例6: isViewable

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static boolean isViewable(Player viewer, Entity target, boolean bypassGameMode) {
    if (target instanceof Player) {
        if (vanishNoPacket) {
            if (manager.isVanished((Player) target)) return false;
        }
        if (!viewer.canSee((Player) target)) return false;
        if (((Player) target).getGameMode() == GameMode.SPECTATOR) return false;
    }
    if (target instanceof LivingEntity) {
        if (((LivingEntity) target).hasPotionEffect(PotionEffectType.INVISIBILITY)) return false;
    }
    return !(viewer.getGameMode() == GameMode.SPECTATOR && !bypassGameMode);
}
 
开发者ID:iso2013,项目名称:MultiLineAPI,代码行数:14,代码来源:VisibilityUtil.java

示例7: onBlockBreak

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockBreak(final BlockBreakEvent event) {
    final Player player = event.getPlayer();
    if(player.getGameMode() == GameMode.CREATIVE) {
        return;
    }
    if(player.getItemInHand().getEnchantments().containsKey(Enchantment.SILK_TOUCH)) return;;
    final Block block = event.getBlock();
    final Location blockLocation = block.getLocation();
    if(block.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(blockLocation.toString())) {
        int count = 1;
        for(int x = -5; x < 5; ++x) {
            for(int y = -5; y < 5; ++y) {
                for(int z = -5; z < 5; ++z) {
                    final Block otherBlock = blockLocation.clone().add((double) x, (double) y, (double) z).getBlock();
                    if(!otherBlock.equals(block) && otherBlock.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(otherBlock.getLocation().toString())) {
                        ++count;
                    }
                }
            }
        }
       
        String message;
        for(Player on : Bukkit.getOnlinePlayers()) {
            if(plugin.getFactionManager().getPlayerFaction(player.getUniqueId()) != null) {
                 message = plugin.getFactionManager().getPlayerFaction(player.getUniqueId()).getRelation(on).toChatColour() + player.getName() + ChatColor.GRAY + " has found " + ChatColor.AQUA + count + ChatColor.GRAY + " diamond(s).";
                on.sendMessage(message);
            }else{
                message = ChatColor.AQUA + "[" + ChatColor.GRAY + "♠" + ChatColor.AQUA + "]" + ChatColor.GRAY + " " + ChatColor.AQUA + player.getName() + ChatColor.GRAY + " has just spotted " + ChatColor.BLUE + count + ChatColor.GRAY +" diamonds!";
                on.sendMessage(message);
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:35,代码来源:FoundDiamondsListener.java

示例8: isPlayerExempt

import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
 * Check if the player is exempt.
 *
 * @param check  the check
 * @param player the check
 * @return if we are exempted or not.
 */
public boolean isPlayerExempt(Player player, CheckType check) {

    // check for common exemptions first.
    boolean hasExemption = checkCommonExemptions(player, check);
    if (hasExemption) {
        return true;
    }

    // iterate through the array of checks that need to be exempted for if we are flying.
    for (CheckType element : EXEMPT_BECAUSE_FLYING) {
        if (!(element.equals(check))) {
            continue;
        }

        if (Arc.COMPATIBILITY) {
            hasExemption = player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight
                    () || player
                    .isFlying();
        } else {
            hasExemption = player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR || player
                    .getAllowFlight
                            () || player
                    .isFlying();
        }
        break;
    }

    return hasExemption;
}
 
开发者ID:Vrekt,项目名称:Arc-v2,代码行数:37,代码来源:ExemptionManager.java

示例9: call

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public void call(Event event) {
	// Causes false positives.
	if (profile.getBehaviour().getMotion().isDescending()) {
		return;
	}

	if (event instanceof PlayerMoveEvent) {
		final Player player = profile.getPlayer();

		if (player.getGameMode() == GameMode.SPECTATOR || player.isInsideVehicle()) {
			/*
			 * If the player is in spectator mode, return out of the method
			 * as the speed function in this GameMode could cause false
			 * positives.
			 */
			return;
		}

		final PlayerMoveEvent pme = (PlayerMoveEvent) event;

		final int speedLevel = profile.getBehaviour().getPotionEffectLevel(PotionEffectType.SPEED);

		// Ignore if the player's speed is higher than two.
		if (speedLevel > 2) {
			return;
		}

		/*
		 * Ignore y for this check. We only want to check speed on the x and
		 * z axes.
		 */
		final Vector from = pme.getFrom().toVector().clone().setY(0.0),
				to = pme.getTo().toVector().clone().setY(0.0);

		double distance = to.distanceSquared(from);

		if (speedLevel > 0) {
			// Take into account speed potions.
			distance -= (distance / 100.0) * (speedLevel * 20.0);
		}

		/*
		 * Walking and flying (but not sprinting): 0.40, Sprinting and
		 * flying: 1.25
		 */
		final long current = System.currentTimeMillis();
		if ((player.isFlying() && player.isSprinting()) || (current
				- profile.getBehaviour().getMotion().getLastFly() <= 500
				&& current - profile.getBehaviour().getMotion()
						.getLastSprint() <= 500) /*
													 * Player is flying and
													 * sprinting and flying
													 * or has been in the
													 * last half a second.
													 */) {
			callback(distance > 1.25);
		} else {
			callback(distance > 0.40);
		}
	}
}
 
开发者ID:davidm98,项目名称:Crescent,代码行数:63,代码来源:SpeedA.java

示例10: rayTraceBlock

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static Block rayTraceBlock(Player player) throws ReflectiveOperationException {
    float distance = player.getGameMode() == GameMode.CREATIVE ? 5.0F : 4.5F;
    Vector start = player.getEyeLocation().toVector();
    Vector end = start.clone().add(player.getEyeLocation().getDirection().multiply(distance));
    return rayTraceBlock(player.getWorld(), start, end, false, false, true);
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:7,代码来源:RayTraceUtils.java

示例11: isPVE

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public boolean isPVE() {
    Player p = getPlayer();
    if ((p.getGameMode() != GameMode.SURVIVAL && p.getGameMode() != GameMode.ADVENTURE) || dead || (region != null && region.dangerLevel <= 1))
        return false;
    return true;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:7,代码来源:PlayerDataRPG.java

示例12: onBlockBreak

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
	Player p = event.getPlayer();
	if ( PermissionInterface.CheckEnabledWorld(p.getLocation())) {
		Block checkBlock;
		checkBlock = event.getBlock();
		int craftBlockId = checkBlock.getTypeId();

		Craft checkCraft = Craft.getCraft(checkBlock.getX(), checkBlock.getY(), checkBlock.getZ());

		if (checkCraft != null) {
			if ((craftBlockId == 46) && (p.getGameMode() != GameMode.CREATIVE)) {
				p.sendMessage(ChatColor.RED + "Can't break vehicle TNT.");
				event.setCancelled(true);
				return;
			} else if ((craftBlockId == 75) || (craftBlockId == 76) || (craftBlockId == 65) || (craftBlockId == 68) || (craftBlockId == 63) || (craftBlockId == 69) || (craftBlockId == 77) || (craftBlockId == 70) || (craftBlockId == 72) || (craftBlockId == 55) || (craftBlockId == 143) || (craftBlockId == 64) || (craftBlockId == 71)) {
				int arrayX = checkBlock.getX() - checkCraft.minX;
				int arrayY = checkBlock.getY() - checkCraft.minY;
				int arrayZ = checkBlock.getZ() - checkCraft.minZ;
				checkCraft.matrix[arrayX][arrayY][arrayZ] = -1;

				if (((craftBlockId == 64) && (checkBlock.getRelative(BlockFace.UP).getTypeId() == 64)) || ((craftBlockId == 71) && (checkBlock.getRelative(BlockFace.UP).getTypeId() == 71))) {
					checkBlock.getRelative(BlockFace.UP).setTypeId(0);
					checkCraft.matrix[arrayX][arrayY + 1][arrayZ] = -1;
				}
				if (((craftBlockId == 64) && (checkBlock.getRelative(BlockFace.DOWN).getTypeId() == 64)) || ((craftBlockId == 71) && (checkBlock.getRelative(BlockFace.DOWN).getTypeId() == 71))) {
					checkBlock.getRelative(BlockFace.DOWN).setTypeId(0);
					checkCraft.matrix[arrayX][arrayY - 1][arrayZ] = -1;
				}
				for (DataBlock complexBlock : checkCraft.complexBlocks) {
					if (complexBlock.locationMatches(arrayX, arrayY, arrayZ)) {
						checkCraft.complexBlocks.remove(complexBlock);
						break;
					}
				}
				for (DataBlock dataBlock : checkCraft.dataBlocks) {
					if (dataBlock.locationMatches(arrayX, arrayY, arrayZ)) {
						checkCraft.dataBlocks.remove(dataBlock);
						break;
					}
				}
			}
		}
	}
}
 
开发者ID:Maximuspayne,项目名称:NavyCraft2-Lite,代码行数:46,代码来源:NavyCraft_BlockListener.java

示例13: getImminentDeath

import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
 * Get the cause of the player's imminent death, or null if they are not about to die
 * NOTE: not idempotent, has the side effect of clearing the recentDamage cache
 */
public @Nullable ImminentDeath getImminentDeath(Player player) {
    // If the player is already dead or in creative mode, we don't care
    if(player.isDead() || player.getGameMode() == GameMode.CREATIVE) return null;

    // If the player was on the ground, or is flying, or is able to fly, they are fine
    if(!(player.isOnGround() || player.isFlying() || player.getAllowFlight())) {
        // If the player is falling, detect an imminent falling death
        double fallDistance = player.getFallDistance();
        Block landingBlock = null;
        int waterDepth = 0;
        Location location = player.getLocation();

        if(location.getY() > 256) {
            // If player is above Y 256, assume they fell at least to there
            fallDistance += location.getY() - 256;
            location.setY(256);
        }

        // Search the blocks directly beneath the player until we find what they would have landed on
        Block block = null;
        for(; location.getY() >= 0; location.add(0, -1, 0)) {
            block = location.getBlock();
            if(block != null) {
                landingBlock = block;

                if(Materials.isWater(landingBlock.getType())) {
                    // If the player falls through water, reset fall distance and inc the water depth
                    fallDistance = -1;
                    waterDepth += 1;

                    // Break if they have fallen through enough water to stop falling
                    if(waterDepth >= BREAK_FALL_WATER_DEPTH) break;
                } else {
                    // If the block is not water, reset the water depth
                    waterDepth = 0;

                    if(Materials.isColliding(landingBlock.getType()) || Materials.isLava(landingBlock.getType())) {
                        // Break if the player hits a solid block or lava
                        break;
                    } else if(landingBlock.getType() == Material.WEB) {
                        // If they hit web, reset their fall distance, but assume they keep falling
                        fallDistance = -1;
                    }
                }
            }

            fallDistance += 1;
        }

        double resistanceFactor = getResistanceFactor(player);
        boolean fireResistance = hasFireResistance(player);

        // Now decide if the landing would have killed them
        if(location.getBlockY() < 0) {
            // The player would have fallen into the void
            return new ImminentDeath(EntityDamageEvent.DamageCause.VOID, location, null, false);
        } else if(landingBlock != null) {
            if(Materials.isColliding(landingBlock.getType()) && player.getHealth() <= resistanceFactor * (fallDistance - SAFE_FALL_DISTANCE)) {
                // The player would have landed on a solid block and taken enough fall damage to kill them
                return new ImminentDeath(EntityDamageEvent.DamageCause.FALL, landingBlock.getLocation().add(0, 0.5, 0), null, false);
            } else if (Materials.isLava(landingBlock.getType()) && resistanceFactor > 0 && !fireResistance) {
                // The player would have landed in lava, and we give the lava the benefit of the doubt
                return new ImminentDeath(EntityDamageEvent.DamageCause.LAVA, landingBlock.getLocation(), landingBlock, false);
            }
        }
    }

    // If we didn't predict a falling death, detect combat log due to recent damage
    Damage damage = this.recentDamage.remove(player);
    if(damage != null && damage.time.plus(RECENT_DAMAGE_THRESHOLD).isAfter(Instant.now())) {
        // Player logged out too soon after taking damage
        return new ImminentDeath(damage.event.getCause(), player.getLocation(), null, true);
    }

    return null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:81,代码来源:CombatLogTracker.java

示例14: onItemClick

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemClick(PlayerInteractEvent event)
{
	if(event.isCancelled()) return;
	if(event.hasItem())
	{
		Player player = event.getPlayer();
		if(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
		{
			ItemStack mainItem = player.getInventory().getItemInMainHand();
			if(mainItem.getType() == Material.GLASS_BOTTLE)
			{
				if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
				{
					if(event.getClickedBlock().getType() == Material.CAULDRON && event.getClickedBlock().getData() != (byte)0)
					{
						Block fire = event.getClickedBlock().getRelative(BlockFace.DOWN);
						event.setCancelled(true);
						
						event.getClickedBlock().setData((byte)((int)event.getClickedBlock().getData() - 1));
						
						ItemStack waterBottle = new ItemStack(Material.POTION, 1);
						
						net.minecraft.server.v1_12_R1.ItemStack nmsStack_bottle = CraftItemStack.asNMSCopy(waterBottle);
				        NBTTagCompound compound_bottle = nmsStack_bottle.getTag();
				        compound_bottle.setString("Potion","minecraft:water");
				        compound_bottle.setInt("HideFlags", 32);
				        nmsStack_bottle.setTag(compound_bottle);
				        waterBottle = CraftItemStack.asBukkitCopy(nmsStack_bottle);
				        
						ItemMeta meta = waterBottle.getItemMeta();

						if(fire != null && fire.getType() == Material.FIRE)
						{
							List<String> lore = Arrays.asList
							(
								ChatColor.RESET + "" + ChatColor.GRAY + Survival.Words.get("Purified")
							);
							meta.setLore(lore);
						}
						waterBottle.setItemMeta(meta);
						
						if(mainItem.getAmount() > 1)
						{
							mainItem.setAmount(mainItem.getAmount() - 1);
							if(player.getInventory().firstEmpty() != -1)
								player.getInventory().addItem(waterBottle);
							else
								player.getWorld().dropItem(player.getLocation(), waterBottle);
						}
						else
						{
							player.getInventory().setItemInMainHand(waterBottle);
						}
					}
				}
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:62,代码来源:CauldronWaterBottle.java

示例15: onBreakSnow

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onBreakSnow(BlockBreakEvent e)
{
	if(e.isCancelled()) return;
	Player player = e.getPlayer();
	if(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
	{
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		switch(mainItem.getType())
		{
			case WOOD_SPADE:
			case GOLD_SPADE:
			case STONE_SPADE:
			case DIAMOND_SPADE:
			case IRON_SPADE:
				Block block = e.getBlock();
				switch(block.getType())
				{
					case SNOW:
						e.setCancelled(true);
						mainItem.setDurability((short) (mainItem.getDurability() + 1));
						if(mainItem.getDurability() >= mainItem.getType().getMaxDurability() + 1)
							player.getInventory().setItemInMainHand(null);
			            player.updateInventory();
			            block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.SNOW_BALL, block.getData() + 1));
			            block.setType(Material.AIR);
						break;
					case SNOW_BLOCK:
						e.setCancelled(true);
						mainItem.setDurability((short) (mainItem.getDurability() + 1));
						if(mainItem.getDurability() >= mainItem.getType().getMaxDurability() + 1)
							player.getInventory().setItemInMainHand(null);
			            player.updateInventory();
			            block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.SNOW_BALL, 8));
			            block.setType(Material.AIR);
			            break;
					default:
				}
				break;
			default:
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:45,代码来源:SnowballThrow.java


注:本文中的org.bukkit.entity.Player.getGameMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。