當前位置: 首頁>>代碼示例>>Java>>正文


Java Player.getTargetBlock方法代碼示例

本文整理匯總了Java中org.bukkit.entity.Player.getTargetBlock方法的典型用法代碼示例。如果您正苦於以下問題:Java Player.getTargetBlock方法的具體用法?Java Player.getTargetBlock怎麽用?Java Player.getTargetBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.entity.Player的用法示例。


在下文中一共展示了Player.getTargetBlock方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: grow

import org.bukkit.entity.Player; //導入方法依賴的package包/類
public static void grow(Player p, int radius) {
    Block target = p.getTargetBlock((HashSet<Byte>) null, 100);
    int radius_squared = radius * radius;
    Block toHandle;
    SchematicUserConfig cfg = getConfig(p);
    ArrayList<Block> list = new ArrayList<Block>();
    for (int x = -radius; x <= radius; x++) {
        for (int z = -radius; z <= radius; z++) {
            toHandle = target.getWorld().getHighestBlockAt(target.getX() + x, target.getZ() + z);
            if (toHandle.getType() == Material.AIR && toHandle.getRelative(BlockFace.DOWN).getType() == Material.GRASS) { // Block beneath is grass
                if (target.getLocation().distanceSquared(toHandle.getLocation()) <= radius_squared) { // Block is in radius
                    double rand = Math.random();
                    if (rand < cfg.growDensity * 5 / 6) {
                        toHandle.setType(Material.LONG_GRASS);
                        toHandle.setData((byte) 1);
                        list.add(toHandle);
                    } else if (rand < cfg.growDensity) {
                        toHandle.setType(Material.RED_ROSE); //0 4 5 6 7 8
                        byte data = (byte) (Math.random() * 6);
                        if (data > 0)
                            data += 3; //1 + 3 = 4, 2 + 3 = 5, ..., 5 + 3 = 8
                        toHandle.setData(data);
                        list.add(toHandle);
                    }
                }
            }
        }
    }
    cfg.lastGrow.add(list);
    if (SchematicManager.getConfig(p).verbose)
        p.sendMessage("Grew with radius " + radius + ".");
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:33,代碼來源:SchematicManager.java

示例2: cast

import org.bukkit.entity.Player; //導入方法依賴的package包/類
@Override
public boolean cast(final Player p, final PlayerDataRPG pd, final int level) {
    int damage = pd.getDamage(true);
    switch (level) {
        case 1:
            damage *= 1.2;
            break;
        case 2:
            damage *= 1.4;
            break;
        case 3:
            damage *= 1.6;
            break;
        case 4:
            damage *= 1.9;
            break;
        case 5:
            damage *= 2.2;
            break;
        case 6:
            damage *= 2.6;
            break;
        case 7:
            damage *= 3.0;
            break;
        case 8:
            damage *= 3.5;
            break;
    }
    Block b = p.getTargetBlock((Set<Material>) null, 20);
    if (b == null) {
        p.sendMessage(ChatColor.RED + "Point at a block to cast Lightning Bolt!");
        return false;
    }
    Location loc = b.getLocation();
    RParticles.sendLightning(p, loc);
    Spell.damageNearby(damage, p, loc, 2.5, new ArrayList<Entity>());
    Spell.notify(p, "You summon a bolt of lightning to strike the ground.");
    return true;
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:41,代碼來源:LightningBolt.java

示例3: tabComplete

import org.bukkit.entity.Player; //導入方法依賴的package包/類
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
    Player player = (Player) sender;
    Block block = player.getTargetBlock((Set<Material>) null, 100);
    if(args.length == 0) {
        return new ArrayList<>(block.getX());
    } else if(args.length == 1){
        return new ArrayList<>(block.getY());
    } else if(args.length == 2){
        return new ArrayList<>(block.getZ());
    } else {
        return new ArrayList<>();
    }
}
 
開發者ID:Warvale,項目名稱:Scorch,代碼行數:15,代碼來源:LootChestCommand.java

示例4: onInventoryClose

import org.bukkit.entity.Player; //導入方法依賴的package包/類
@EventHandler
public void onInventoryClose(InventoryCloseEvent e)
{
	if (!(e.getPlayer() instanceof Player))
		return;
	final Player p = (Player) e.getPlayer();

	if (!p.hasMetadata("shared_workbench"))
		return;
	if (e.getInventory().getType() == InventoryType.WORKBENCH)
	{
		// Workaround to get the accessed WorkBench
		final Block workbench = p.getTargetBlock((Set<Material>) null, 8);

		if (!workbench.hasMetadata("shared_players") || workbench.getType() != Material.WORKBENCH)
		{
			if (p.getOpenInventory().getTopInventory() != null)
				p.getOpenInventory().getTopInventory().clear();
			p.removeMetadata("shared_workbench", Survival.instance);
			
			return;
		}

		@SuppressWarnings("unchecked")
		List<UUID> list = (workbench.getMetadata("shared_players").get(0).value() instanceof List<?>) ? (List<UUID>)workbench.getMetadata("shared_players").get(0).value() : new ArrayList<UUID>();
		
		list.remove(p.getUniqueId());
		
		if (list.isEmpty())
			workbench.removeMetadata("shared_players", Survival.instance);
		else
		{
			e.getInventory().clear();
			workbench.setMetadata("shared_players", new FixedMetadataValue(Survival.instance, list));
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:38,代碼來源:WorkbenchShare.java

示例5: execute

import org.bukkit.entity.Player; //導入方法依賴的package包/類
public boolean execute(CommandSender sender, String[] args) {
  	if (args.length != 1) {
  		Chat.player(sender, "&cPlease include the name.");
  		return true;
  	}
  	
  	Course c = Course.get(args[0]);
  	if (c == null) {
  		Chat.player(sender, "&7[Parkour] Couldn't find the course, " + args[0]);
  		return true;
  	}
  	
  	Player p = (Player) sender;
  	
Block b = p.getTargetBlock(null, 10);
if (b == null || b.getType() != Material.STONE_BUTTON) {
	Chat.player(sender, "&2[SG] &cThat is not a button");
	return true;
}
Parkour.getInstance().getConfigAPI().set(c.getName() + ".button.x", b.getX());
Parkour.getInstance().getConfigAPI().set(c.getName() + ".button.y", b.getY());
Parkour.getInstance().getConfigAPI().set(c.getName() + ".button.z", b.getZ());
Parkour.getInstance().getConfigAPI().set(c.getName() + ".button.world", b.getWorld().getName());
Chat.player(sender, "&7[Parkour] &aStart button added to " + c.getName());
  	Parkour.getInstance().saveConfig();
  	Parkour.getInstance().loadCourses();
  	
      return true;
  }
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:30,代碼來源:ParkourStartCmd.java

示例6: execute

import org.bukkit.entity.Player; //導入方法依賴的package包/類
public boolean execute(CommandSender sender, String[] args) {
  	if (args.length != 1) {
  		Chat.player(sender, "&cPlease include the name.");
  		return true;
  	}
  	
  	Course c = Course.get(args[0]);
  	if (c == null) {
  		Chat.player(sender, "&7[Parkour] Couldn't find the course, " + args[0]);
  		return true;
  	}
  	
  	Player p = (Player) sender;
  	
Block b = p.getTargetBlock(null, 10);
if (b == null || b.getType() != Material.STONE_BUTTON) {
	Chat.player(sender, "&2[SG] &cThat is not a button");
	return true;
}
Parkour.getInstance().getConfigAPI().set(c.getName() + ".end.x", b.getX());
Parkour.getInstance().getConfigAPI().set(c.getName() + ".end.y", b.getY());
Parkour.getInstance().getConfigAPI().set(c.getName() + ".end.z", b.getZ());
Parkour.getInstance().getConfigAPI().set(c.getName() + ".end.world", b.getWorld().getName());
Chat.player(sender, "&7[Parkour] &aEnd button added to " + c.getName());
  	Parkour.getInstance().saveConfig();
  	Parkour.getInstance().loadCourses();
  	
      return true;
  }
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:30,代碼來源:ParkourEndCmd.java

示例7: commandLogic

import org.bukkit.entity.Player; //導入方法依賴的package包/類
@Override
protected boolean commandLogic(CommandSender sender, Command command, String label, String[] args) {
    Player player = (Player) sender;
    Block block = player.getTargetBlock(null, 50);

    if (args.length == 0) {
        player.sendMessage(block.toString());
        return true;
    }

    return doReflectionLookups(sender, args, block);
}
 
開發者ID:zachbr,項目名稱:Debuggery,代碼行數:13,代碼來源:BlockCommand.java

示例8: handleLightning

import org.bukkit.entity.Player; //導入方法依賴的package包/類
private void handleLightning(Player player, Rune rune) {
	@SuppressWarnings("deprecation")
	Block block = player.getTargetBlock((HashSet<Byte>) null, 15);
	if(!Utility.isPVPEnabled(block.getLocation())) {
		return;
	}
	
	block.getWorld().strikeLightning(block.getLocation());
	for(Entity e : block.getWorld().getEntities()) {
		if(!(e instanceof Player)) {
			continue;
		}
		Player target = (Player) e;
		if(!Utility.canAttack(player, target)) {
			continue;
		}
		double distance = target.getLocation().distance(block.getLocation());
		double damage = 0;
		if(distance < 1) {
			damage = 16;
		}
		else if(distance <= 3) {
			damage = 10;
		}
		
		if(damage < 1)
			continue;
		
		if(target.getHealth() > damage)
			target.setHealth(target.getHealth() - damage);
		else
			target.damage(1000000, player);
		target.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_LIGHTNING.toString()
			.replaceAll("%s", player.getName()));
	}
	finish(player, false);
}
 
開發者ID:benNek,項目名稱:AsgardAscension,代碼行數:38,代碼來源:RuneManager.java

示例9: getSignLookat

import org.bukkit.entity.Player; //導入方法依賴的package包/類
public Sign getSignLookat(CommandSender sender) {
    Player p = asPlayer(sender);
    Block b = p.getTargetBlock((Set<Material>) null, 5);// TODO use nms rayTrace

    if (b == null || !b.getType().isBlock() || (b.getType() != Material.WALL_SIGN && b.getType() != Material.SIGN_POST)) {
        throw new BadCommandException("user.error.not_sign");
    }
    return (Sign)b.getState();
}
 
開發者ID:NyaaCat,項目名稱:CapCat,代碼行數:10,代碼來源:SignCommands.java

示例10: cast

import org.bukkit.entity.Player; //導入方法依賴的package包/類
@Override
public boolean cast(final Player p, final PlayerDataRPG pd, int level) {
    int damage = pd.getDamage(true);
    switch (level) {
        case 1:
            damage *= 1.1;
            break;
        case 2:
            damage *= 1.2;
            break;
        case 3:
            damage *= 1.3;
            break;
        case 4:
            damage *= 1.4;
            break;
        case 5:
            damage *= 1.5;
            break;
        case 6:
            damage *= 1.6;
            break;
        case 7:
            damage *= 1.7;
            break;
        case 8:
            damage *= 1.8;
            break;
        case 9:
            damage *= 1.9;
            break;
        case 10:
            damage *= 2.0;
            break;
    }
    final int fDamage = damage;
    RSound.playSound(p, Sound.ENTITY_ARROW_SHOOT);
    Block b = p.getTargetBlock((Set<Material>) null, 15);
    Location loc = b.getLocation();
    for (int x = -3; x <= 3; x++) {
        for (int z = -3; z <= 3; z++) {
            final Location currentLoc = loc.clone();
            currentLoc.setX(loc.getX() + x - 1);
            currentLoc.setZ(loc.getZ() + z);
            currentLoc.setY(loc.getY() + RMath.randInt(4, 6));
            Location loc2 = loc.clone();
            loc2.setX(loc.getX() + x);
            loc2.setZ(loc.getZ() + z);
            final Vector v = loc2.toVector().subtract(currentLoc.toVector()).normalize();
            int count = (int) (Math.random() * 3 + 1);
            for (int k = 0; k < count; k++) {
                if (Math.random() < 0.7) {
                    RScheduler.schedule(Spell.plugin, new Runnable() {
                        public void run() {
                            Projectile arrow = ((Projectile) (currentLoc.getWorld().spawnEntity(currentLoc, EntityType.ARROW)));
                            arrow.setVelocity(v);
                            arrow.setShooter(p);
                            arrow.setMetadata(RMetadata.META_DAMAGE, new FixedMetadataValue(Spell.plugin, fDamage));
                        }
                    }, (int) (Math.random() * RTicks.seconds(2)));
                }
            }
        }
    }
    Spell.notify(p, "A rain of arrows showers down from the skies.");
    return true;
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:68,代碼來源:ArrowRain.java

示例11: getTargetBlockOfPlayer

import org.bukkit.entity.Player; //導入方法依賴的package包/類
Block getTargetBlockOfPlayer(Player player) {
    return player.getTargetBlock((Set<Material>) null, 10);
}
 
開發者ID:Deltik,項目名稱:SignEdit,代碼行數:4,代碼來源:SignSubcommand.java


注:本文中的org.bukkit.entity.Player.getTargetBlock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。