下面列出了怎么用org.bukkit.material.Bed的API类实例代码及写法,或者点击链接到github查看源代码。
private void dropTargetBlock(Block targetBlock) {
if (targetBlock.getType().equals(Material.BED_BLOCK)) {
Block bedHead;
Block bedFeet;
Bed bedBlock = (Bed) targetBlock.getState().getData();
if (!bedBlock.isHeadOfBed()) {
bedFeet = targetBlock;
bedHead = Utils.getBedNeighbor(bedFeet);
} else {
bedHead = targetBlock;
bedFeet = Utils.getBedNeighbor(bedHead);
}
if (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_12")) {
bedFeet.setType(Material.AIR);
} else {
bedHead.setType(Material.AIR);
}
} else {
targetBlock.setType(Material.AIR);
}
}
@Override
public boolean isBedHead(Block block) {
MaterialData data = block.getState().getData();
if (!(data instanceof Bed)) {
throw new IllegalArgumentException("Block is not Bed");
}
return ((Bed) data).isHeadOfBed();
}
public boolean handleDestroyTargetMaterial(Player p, Block block) {
Team team = this.getPlayerTeam(p);
if (team == null) {
return false;
}
Team bedDestroyTeam = null;
Block bedBlock = team.getHeadTarget();
if (block.getType().equals(Material.BED_BLOCK)) {
Block breakBlock = block;
Block neighbor = null;
Bed breakBed = (Bed) breakBlock.getState().getData();
if (!breakBed.isHeadOfBed()) {
neighbor = breakBlock;
breakBlock = Utils.getBedNeighbor(neighbor);
} else {
neighbor = Utils.getBedNeighbor(breakBlock);
}
if (bedBlock.equals(breakBlock)) {
p.sendMessage(
ChatWriter
.pluginMessage(ChatColor.RED + BedwarsRel._l(p, "ingame.blocks.ownbeddestroy")));
return false;
}
bedDestroyTeam = this.getTeamOfBed(breakBlock);
if (bedDestroyTeam == null) {
return false;
}
this.dropTargetBlock(block);
} else {
if (bedBlock.equals(block)) {
p.sendMessage(
ChatWriter
.pluginMessage(ChatColor.RED + BedwarsRel._l(p, "ingame.blocks.ownbeddestroy")));
return false;
}
bedDestroyTeam = this.getTeamOfBed(block);
if (bedDestroyTeam == null) {
return false;
}
this.dropTargetBlock(block);
}
// set statistics
if (BedwarsRel.getInstance().statisticsEnabled()) {
PlayerStatistic statistic = BedwarsRel.getInstance().getPlayerStatisticManager()
.getStatistic(p);
statistic.setCurrentDestroyedBeds(statistic.getCurrentDestroyedBeds() + 1);
statistic.setCurrentScore(statistic.getCurrentScore() + BedwarsRel.getInstance()
.getIntConfig("statistics.scores.bed-destroy", 25));
}
// reward when destroy bed
if (BedwarsRel.getInstance().getBooleanConfig("rewards.enabled", false)) {
List<String> commands =
BedwarsRel.getInstance().getConfig().getStringList("rewards.player-destroy-bed");
BedwarsRel.getInstance()
.dispatchRewardCommands(commands, ImmutableMap.of("{player}", p.getName(),
"{score}",
String.valueOf(
BedwarsRel.getInstance().getIntConfig("statistics.scores.bed-destroy", 25))));
}
BedwarsTargetBlockDestroyedEvent targetBlockDestroyedEvent =
new BedwarsTargetBlockDestroyedEvent(this, p, bedDestroyTeam);
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(targetBlockDestroyedEvent);
for (Player aPlayer : this.getPlayers()) {
if (aPlayer.isOnline()) {
aPlayer.sendMessage(
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
._l(aPlayer, "ingame.blocks.beddestroyed",
ImmutableMap.of("team",
bedDestroyTeam.getChatColor() + bedDestroyTeam.getName() + ChatColor.RED,
"player",
Game.getPlayerWithTeamString(p, team, ChatColor.RED)))));
}
}
this.broadcastSound(
Sound.valueOf(
BedwarsRel.getInstance().getStringConfig("bed-sound", "ENDERDRAGON_GROWL")
.toUpperCase()),
30.0F, 10.0F);
this.updateScoreboard();
return true;
}
@Override
public boolean execute(CommandSender sender, ArrayList<String> args) {
if (!super.hasPermission(sender)) {
return false;
}
Player player = (Player) sender;
String team = args.get(1);
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
if (game == null) {
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
+ BedwarsRel
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
return false;
}
if (game.getState() == GameState.RUNNING) {
sender.sendMessage(
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
._l(sender, "errors.notwhilegamerunning")));
return false;
}
Team gameTeam = game.getTeam(team);
if (gameTeam == null) {
player.sendMessage(
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamnotfound")));
return false;
}
Class<?> hashsetType = Utils.getGenericTypeOfParameter(player.getClass(), "getTargetBlock", 0);
Method targetBlockMethod = this.getTargetBlockMethod(player);
Block targetBlock = null;
if (targetBlockMethod != null) {
targetBlock = this.getTargetBlock(targetBlockMethod, hashsetType, player);
}
Block standingBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
if (targetBlock == null || standingBlock == null) {
player.sendMessage(
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.bedtargeting")));
return false;
}
Material targetMaterial = game.getTargetMaterial();
if (targetBlock.getType() != targetMaterial && standingBlock.getType() != targetMaterial) {
player.sendMessage(
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.bedtargeting")));
return false;
}
Block theBlock = null;
if (targetBlock.getType() == targetMaterial) {
theBlock = targetBlock;
} else {
theBlock = standingBlock;
}
if (targetMaterial.equals(Material.BED_BLOCK)) {
Block neighbor = null;
Bed theBed = (Bed) theBlock.getState().getData();
if (!theBed.isHeadOfBed()) {
neighbor = theBlock;
theBlock = Utils.getBedNeighbor(neighbor);
} else {
neighbor = Utils.getBedNeighbor(theBlock);
}
gameTeam.setTargets(theBlock, neighbor);
} else {
gameTeam.setTargets(theBlock, null);
}
player.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
._l(player, "success.bedset",
ImmutableMap
.of("team", gameTeam.getChatColor() + gameTeam.getName() + ChatColor.GREEN))));
return true;
}