本文整理汇总了Java中org.bukkit.block.CommandBlock.setCommand方法的典型用法代码示例。如果您正苦于以下问题:Java CommandBlock.setCommand方法的具体用法?Java CommandBlock.setCommand怎么用?Java CommandBlock.setCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.block.CommandBlock
的用法示例。
在下文中一共展示了CommandBlock.setCommand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateCmdBlockWithOffHand
import org.bukkit.block.CommandBlock; //导入方法依赖的package包/类
private void generateCmdBlockWithOffHand(Location l, ArmorStand as) {
Location loc = as.getLocation();
int dSlots = getDisabledSlots(as);
String hand, boots, legs, chest, helm, offHand;
int handDmg, offHandDmg;
hand = as.getEquipment().getItemInMainHand() == null ? "air" : getNmsName(as.getEquipment().getItemInMainHand().getType());
offHand = as.getEquipment().getItemInOffHand() == null ? "air" : getNmsName(as.getEquipment().getItemInOffHand().getType());
boots = as.getBoots() == null ? "air" : getNmsName(as.getBoots().getType());
legs = as.getLeggings() == null ? "air" : getNmsName(as.getLeggings().getType());
chest = as.getChestplate() == null ? "air" : getNmsName(as.getChestplate().getType());
helm = as.getHelmet() == null ? "air" : getNmsName(as.getHelmet().getType());
handDmg = as.getEquipment().getItemInMainHand() == null ? 0 : as.getEquipment().getItemInMainHand().getDurability();
offHandDmg = as.getEquipment().getItemInOffHand() == null ? 0 : as.getEquipment().getItemInOffHand().getDurability();
int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability();
int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability();
int chestDmg = as.getChestplate() == null ? 0 : as.getChestplate().getDurability();
int helmDmg = as.getHelmet() == null ? 0 : as.getHelmet().getDurability();
EulerAngle he = as.getHeadPose();
EulerAngle ll = as.getLeftLegPose();
EulerAngle rl = as.getRightLegPose();
EulerAngle la = as.getLeftArmPose();
EulerAngle ra = as.getRightArmPose();
EulerAngle bo = as.getBodyPose();
String cmd = "summon " + summonEntityName + " " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
+ (as.isVisible() ? "" : "Invisible:1,")
+ (as.hasBasePlate() ? "" : "NoBasePlate:1,")
+ (as.hasGravity() ? "" : "NoGravity:1,")
+ (as.hasArms() ? "ShowArms:1," : "")
+ (as.isSmall() ? "Small:1," : "")
+ (isInvulnerable(as) ? "Invulnerable:1," : "")
+ (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
+ (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
+ (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\","))
+ (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],"))
+ (as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : (
"ArmorItems:["
+ "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + getItemStackTags(as.getBoots()) + "},"
+ "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + getItemStackTags(as.getLeggings()) + "},"
+ "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + getItemStackTags(as.getChestplate()) + "},"
+ "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + getItemStackTags(as.getHelmet()) + skullOwner(as.getHelmet()) + "}],"))
+ (as.getEquipment().getItemInMainHand() == null && as.getEquipment().getItemInOffHand() == null ? "" : (
"HandItems:["
+ "{id:" + hand + ",Count:" + as.getEquipment().getItemInMainHand().getAmount() + ",Damage:" + handDmg + getItemStackTags(as.getEquipment().getItemInMainHand()) + "},"
+ "{id:" + offHand + ",Count:" + as.getEquipment().getItemInOffHand().getAmount() + ",Damage:" + offHandDmg + getItemStackTags(as.getEquipment().getItemInOffHand()) + "}],"))
+ "Pose:{"
+ (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],"))
+ (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],"))
+ (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],"))
+ (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],"))
+ (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],"))
+ "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}";
Block b = l.getBlock();
b.setType(Material.COMMAND);
//noinspection deprecation
b.setData((byte) 0);
CommandBlock cb = (CommandBlock) b.getState();
cb.setCommand(cmd);
cb.update();
}
示例2: generateCmdBlockWithoutOffHand
import org.bukkit.block.CommandBlock; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void generateCmdBlockWithoutOffHand(Location l, ArmorStand as) {
Location loc = as.getLocation();
int dSlots = Main.nms.getDisabledSlots(as);
String hand, boots, legs, chest, helm;
int handDmg;
hand = getItemInMainHand(as) == null ? "0" : String.valueOf(getItemInMainHand(as).getTypeId());
boots = as.getBoots() == null ? "0" : String.valueOf(as.getBoots().getTypeId());
legs = as.getLeggings() == null ? "0" : String.valueOf(as.getLeggings().getTypeId());
chest = as.getChestplate() == null ? "0" : String.valueOf(as.getChestplate().getTypeId());
helm = as.getHelmet() == null ? "0" : String.valueOf(as.getHelmet().getTypeId());
handDmg = getItemInMainHand(as) == null ? 0 : getItemInMainHand(as).getDurability();
int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability();
int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability();
int chestDmg = as.getChestplate() == null ? 0 : as.getChestplate().getDurability();
int helmDmg = as.getHelmet() == null ? 0 : as.getHelmet().getDurability();
EulerAngle he = as.getHeadPose();
EulerAngle ll = as.getLeftLegPose();
EulerAngle rl = as.getRightLegPose();
EulerAngle la = as.getLeftArmPose();
EulerAngle ra = as.getRightArmPose();
EulerAngle bo = as.getBodyPose();
String cmd = "summon ArmorStand " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
+ (as.isVisible() ? "" : "Invisible:1,")
+ (as.hasBasePlate() ? "" : "NoBasePlate:1,")
+ (as.hasGravity() ? "" : "NoGravity:1,")
+ (as.hasArms() ? "ShowArms:1," : "")
+ (as.isSmall() ? "Small:1," : "")
+ (Main.nms.isInvulnerable(as) ? "Invulnerable:1," : "")
+ (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
+ (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
+ (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\","))
+ (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],"))
+ (getItemInMainHand(as) == null && as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : (
"Equipment:["
+ "{id:" + hand + ",Count:" + getItemInMainHand(as).getAmount() + ",Damage:" + handDmg + getItemStackTags(getItemInMainHand(as)) + "},"
+ "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + getItemStackTags(as.getBoots()) + "},"
+ "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + getItemStackTags(as.getLeggings()) + "},"
+ "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + getItemStackTags(as.getChestplate()) + "},"
+ "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + getItemStackTags(as.getHelmet()) + skullOwner(as.getHelmet()) + "}],"))
+ "Pose:{"
+ (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],"))
+ (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],"))
+ (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],"))
+ (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],"))
+ (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],"))
+ "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}";
Block b = l.getBlock();
b.setType(Material.COMMAND);
b.setData((byte) 0);
CommandBlock cb = (CommandBlock) b.getState();
cb.setCommand(cmd);
cb.update();
}
示例3: modify
import org.bukkit.block.CommandBlock; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void modify(Block block, boolean applyPhysics) {
if (!isValid) return;
try {
BlockState blockState = block.getState();
// Clear chests so they don't dump their contents.
if (blockState instanceof InventoryHolder) {
NMSUtils.clearItems(block.getLocation());
}
if (material != null) {
byte blockData = data != null ? (byte)(short)data : block.getData();
block.setTypeIdAndData(material.getId(), blockData, applyPhysics);
blockState = block.getState();
}
// Set tile entity data first
// Command blocks still prefer internal data for parameterized commands
if (blockState != null && blockState instanceof CommandBlock && extraData != null && extraData instanceof BlockCommand) {
CommandBlock command = (CommandBlock)blockState;
BlockCommand commandData = (BlockCommand)extraData;
command.setCommand(commandData.command);
if (commandData.customName != null) {
command.setName(commandData.customName);
}
command.update();
} else if (extraData != null && extraData instanceof BlockTileEntity) {
// Tile entity data overrides everything else, and may replace all of this in the future.
NMSUtils.setTileEntityData(block.getLocation(), ((BlockTileEntity) extraData).data);
} else if (blockState != null && (material == Material.STANDING_BANNER || material == Material.WALL_BANNER) && extraData != null && extraData instanceof BlockBanner) {
if (blockState != null && blockState instanceof Banner) {
BlockBanner bannerData = (BlockBanner)extraData;
Banner banner = (Banner)blockState;
if (bannerData.patterns != null)
{
banner.setPatterns(bannerData.patterns);
}
if (bannerData.baseColor != null)
{
banner.setBaseColor(bannerData.baseColor);
}
}
blockState.update(true, false);
} else if (blockState != null && blockState instanceof Skull && extraData != null && extraData instanceof BlockSkull) {
Skull skull = (Skull)blockState;
BlockSkull skullData = (BlockSkull)extraData;
if (skullData.skullType != null) {
skull.setSkullType(skullData.skullType);
}
if (skullData.rotation != null) {
skull.setRotation(skullData.rotation);
}
if (skullData.profile != null) {
CompatibilityUtils.setSkullProfile(skull, skullData.profile);
}
skull.update(true, false);
} else if (blockState != null && blockState instanceof CreatureSpawner && extraData != null && extraData instanceof BlockMobSpawner) {
BlockMobSpawner spawnerData = (BlockMobSpawner)extraData;
if (spawnerData.mobName != null && !spawnerData.mobName.isEmpty())
{
CreatureSpawner spawner = (CreatureSpawner)blockState;
spawner.setCreatureTypeByName(spawnerData.mobName);
spawner.update();
}
}
} catch (Exception ex) {
Bukkit.getLogger().warning("Error updating block state: " + ex.getMessage());
}
}
示例4: applyTile
import org.bukkit.block.CommandBlock; //导入方法依赖的package包/类
private void applyTile(BlockState blockState) {
boolean requiresUpdate = false;
// InventoryHolder
if (blockState instanceof InventoryHolder && _contents != null) {
InventoryHolder holder = (InventoryHolder)blockState;
Inventory inventory = holder.getInventory();
inventory.setContents(_contents);
requiresUpdate = true;
}
// CommandBlock
if (blockState instanceof CommandBlock) {
CommandBlock commandBlock = (CommandBlock)blockState;
if (_commandName != null)
commandBlock.setName(_commandName);
if (_command != null)
commandBlock.setCommand(_command);
requiresUpdate = true;
}
// CreatureSpawner
if (blockState instanceof CreatureSpawner) {
CreatureSpawner spawner = (CreatureSpawner)blockState;
if (_creatureTypeName != null) {
spawner.setCreatureTypeByName(_creatureTypeName);
spawner.setDelay(_creatureDelay);
}
requiresUpdate = true;
}
if (blockState instanceof NoteBlock && _noteTone != null) {
NoteBlock noteBlock = (NoteBlock)blockState;
Note note = new Note(_noteOctave, _noteTone, _noteSharped);
noteBlock.setNote(note);
requiresUpdate = true;
}
if (blockState instanceof Sign && _signLines != null) {
Sign sign = (Sign)blockState;
for (int i=0; i < 4; i++)
sign.setLine(i, _signLines[i]);
requiresUpdate = true;
}
if (blockState instanceof Skull && _skullType != null) {
Skull skull = (Skull)blockState;
skull.setSkullType(_skullType);
skull.setRotation(_skullRotation);
skull.setOwner(_skullOwner);
requiresUpdate = true;
}
if (requiresUpdate) {
blockState.update(true);
}
}