本文整理汇总了Java中cn.nukkit.entity.data.EntityMetadata类的典型用法代码示例。如果您正苦于以下问题:Java EntityMetadata类的具体用法?Java EntityMetadata怎么用?Java EntityMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityMetadata类属于cn.nukkit.entity.data包,在下文中一共展示了EntityMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: spawnTo
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
@Override
public void spawnTo(Player player) {
AddEntityPacket packet = new AddEntityPacket();
packet.type = getNetworkId();
packet.entityUniqueId = this.getId();
packet.entityRuntimeId = getId();
packet.x = (float) this.x;
packet.y = (float) this.y;
packet.z = (float) this.z;
packet.speedX = (float) this.motionX;
packet.speedY = (float) this.motionY;
packet.speedZ = (float) this.motionZ;
packet.metadata = new EntityMetadata();
player.dataPacket(packet);
//this.sendData(player);
super.spawnTo(player);
}
示例2: createBossEntity
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
private void createBossEntity() {
AddEntityPacket pkAdd = new AddEntityPacket();
pkAdd.type = EntityCreeper.NETWORK_ID;
pkAdd.entityUniqueId = bossBarId;
pkAdd.entityRuntimeId = bossBarId;
pkAdd.x = (float) player.x;
pkAdd.y = (float) -10; // Below the bedrock
pkAdd.z = (float) player.z;
pkAdd.speedX = 0;
pkAdd.speedY = 0;
pkAdd.speedZ = 0;
pkAdd.metadata = new EntityMetadata()
// Default Metadata tags
.putLong(Entity.DATA_FLAGS, 0)
.putShort(Entity.DATA_AIR, 400)
.putShort(Entity.DATA_MAX_AIR, 400)
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
.putString(Entity.DATA_NAMETAG, text) // Set the entity name
.putFloat(Entity.DATA_SCALE, 0); // And make it invisible
player.dataPacket(pkAdd);
}
示例3: spawnTo
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
@Override
public void spawnTo(Player player) {
AddEntityPacket packet = new AddEntityPacket();
packet.type = getNetworkId();
packet.eid = getId();
packet.x = (float) this.x;
packet.y = (float) this.y;
packet.z = (float) this.z;
packet.speedX = (float) this.motionX;
packet.speedY = (float) this.motionY;
packet.speedZ = (float) this.motionZ;
packet.metadata = new EntityMetadata();
player.dataPacket(packet);
//this.sendData(player);
super.spawnTo(player);
}
示例4: spawnTo
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
public void spawnTo(Player player) {
if (pos.level == player.level) {
AddPlayerPacket pk = new AddPlayerPacket();
pk.uuid = UUID.randomUUID();
pk.username = "";
pk.item = Item.get(Item.AIR);
pk.entityUniqueId = eid;
pk.entityRuntimeId = eid;
pk.x = (float) pos.x + 0.5f;
pk.y = (float) pos.y - 1.7f;
pk.z = (float) pos.z + 0.5f;
pk.speedX = 0;
pk.speedY = 0;
pk.speedZ = 0;
pk.yaw = 0;
pk.pitch = 0;
long flags = 0;
flags |= 1 << Entity.DATA_FLAG_INVISIBLE;
flags |= 1 << Entity.DATA_FLAG_CAN_SHOW_NAMETAG;
flags |= 1 << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG;
flags |= 1 << Entity.DATA_FLAG_IMMOBILE;
pk.metadata = new EntityMetadata().putLong(Entity.DATA_FLAGS, flags).putString(Entity.DATA_NAMETAG, text.replace("<br>", "\n").replace("\\n", "\n"))
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1).putByte(Entity.DATA_LEAD, 0);
player.dataPacket(pk);
}
}
示例5: getAsAddPacket
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
/**
* AddPlayerPacketとして取得します
* @return AddPlayerPacket
*/
public AddPlayerPacket getAsAddPacket() {
AddPlayerPacket pk = new AddPlayerPacket();
pk.uuid = UUID.randomUUID();
pk.username = "text";
pk.entityUniqueId = eid;
pk.entityRuntimeId = eid;
pk.x = x.floatValue();
pk.y = y.floatValue();
pk.z = z.floatValue();
pk.speedX = 0.0f;
pk.speedY = 0.0f;
pk.speedZ = 0.0f;
pk.pitch = 0.0f;
pk.yaw = 0.0f;
pk.item = Item.get(Item.AIR);
long flags = 0;
flags |= 1 << Entity.DATA_FLAG_CAN_SHOW_NAMETAG;
flags |= 1 << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG;
flags |= 1 << Entity.DATA_FLAG_IMMOBILE;
if (invisible) {
flags |= 1 << Entity.DATA_FLAG_INVISIBLE;
}
String text = (this.text.length() == 0)? "" : "\n" + this.text;
pk.metadata = new EntityMetadata();
pk.metadata.putLong(Entity.DATA_FLAGS, flags);
pk.metadata.putString(Entity.DATA_TYPE_STRING, title + TextFormat.RESET + TextFormat.WHITE + text);
pk.metadata.putFloat(Entity.DATA_SCALE, 0.0f);
return pk;
}
示例6: getAsAddPacket
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
/**
* AddPlayerPacketとして取得します
* @return AddPlayerPacket
*/
public AddPlayerPacket getAsAddPacket() {
AddPlayerPacket pk = new AddPlayerPacket();
pk.uuid = UUID.randomUUID();
pk.username = "text";
pk.entityUniqueId = eid;
pk.entityRuntimeId = eid;
pk.x = x.floatValue();
pk.y = y.floatValue();
pk.z = z.floatValue();
pk.speedX = 0.0f;
pk.speedY = 0.0f;
pk.speedZ = 0.0f;
pk.pitch = 0.0f;
pk.yaw = 0.0f;
pk.item = Item.get(Item.AIR);
long flags = 0;
flags |= 1 << Entity.DATA_FLAG_CAN_SHOW_NAMETAG;
flags |= 1 << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG;
flags |= 1 << Entity.DATA_FLAG_IMMOBILE;
if (invisible) {
flags |= 1 << Entity.DATA_FLAG_INVISIBLE;
}
String text = (this.text.isEmpty())? "" : "\n" + this.text;
pk.metadata = new EntityMetadata();
pk.metadata.putLong(Entity.DATA_FLAGS, flags);
pk.metadata.putString(Entity.DATA_TYPE_STRING, title + TextFormat.RESET + TextFormat.WHITE + text);
pk.metadata.putFloat(Entity.DATA_SCALE, 0.0f);
return pk;
}
示例7: addBossBar
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
/**
* @param players ServerPlayers
* @param title Text
* @return EntityId
*/
public static long addBossBar(Map<UUID, Player> players, String title) {
if (players.isEmpty()) return 1L;
long eid = Entity.entityCount++;
AddEntityPacket pk = new AddEntityPacket();
pk.entityRuntimeId = pk.entityUniqueId = eid;
pk.type = 52;
pk.yaw = 0;
pk.pitch = 0;
EntityMetadata metadata = new EntityMetadata()
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
.putLong(Entity.DATA_FLAGS, 0 ^ 1 << Entity.DATA_FLAG_SILENT ^ 1 << Entity.DATA_FLAG_INVISIBLE ^ 1 << Entity.DATA_FLAG_NO_AI)
.putFloat(Entity.DATA_SCALE, 0)
.putString(Entity.DATA_NAMETAG, title)
.putString(Entity.DATA_TYPE_STRING, title)
.putFloat(Entity.DATA_BOUNDING_BOX_WIDTH, 0)
.putFloat(Entity.DATA_BOUNDING_BOX_HEIGHT, 0);
pk.speedX = 0;
pk.speedY = 0;
pk.speedZ = 0;
pk.metadata = metadata;
AddEntityPacket pkp;
Player player;
for (Map.Entry<UUID, Player> entry : players.entrySet()) {
player = entry.getValue();
pkp = (AddEntityPacket) pk.clone();
pkp.x = (float) player.getX();
pkp.y = (float) player.getY() - 28;
pkp.z = (float) player.getZ();
player.dataPacket(pkp);
pkp.clean();
pkp = null;
}
BossEventPacket bpk = new BossEventPacket(); // This updates the bar
bpk.eid = eid;
bpk.type = 0;
Server.broadcastPacket(players.values(), bpk);
return eid;
}
示例8: sendBossBarToPlayer
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
/**
* @param player Who Player
* @param eid EntityId
* @param title Text
*/
public static void sendBossBarToPlayer(Player player, long eid, String title) {
AddEntityPacket packet = new AddEntityPacket();
packet.entityRuntimeId = packet.entityUniqueId = eid;
packet.type = 52;
packet.yaw = 0;
packet.pitch = 0;
EntityMetadata metadata = new EntityMetadata()
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
.putLong(Entity.DATA_FLAGS, 0 ^ 1 << Entity.DATA_FLAG_SILENT ^ 1 << Entity.DATA_FLAG_INVISIBLE ^ 1 << Entity.DATA_FLAG_NO_AI)
.putFloat(Entity.DATA_SCALE, 0)
.putString(Entity.DATA_NAMETAG, title)
.putString(Entity.DATA_TYPE_STRING, title)
.putFloat(Entity.DATA_BOUNDING_BOX_WIDTH, 0)
.putFloat(Entity.DATA_BOUNDING_BOX_HEIGHT, 0);
packet.metadata = metadata;
packet.x = (float) player.getX();
packet.y = (float) player.getY();
packet.z = (float) player.getZ();
packet.speedX = 0;
packet.speedY = 0;
packet.speedZ = 0;
player.dataPacket(packet);
BossEventPacket bpk = new BossEventPacket();
bpk.eid = eid;
bpk.type = 0;
player.dataPacket(bpk);
}
示例9: setTitle
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
/**
* @param title Text
* @param eid EntityId
*/
public static void setTitle(String title, long eid) {
if (BossBarAPI.getPlugin().getServer().getOnlinePlayers().keySet().toArray().length < 0) return;
SetEntityDataPacket npk = new SetEntityDataPacket();
npk.metadata = new EntityMetadata()
.putString(Entity.DATA_NAMETAG, title);
npk.eid = eid;
Server.broadcastPacket(BossBarAPI.getPlugin().getServer().getOnlinePlayers().values(), npk);
BossEventPacket bpk = new BossEventPacket(); // This updates the bar
bpk.eid = eid;
bpk.type = 0;
Server.broadcastPacket(BossBarAPI.getPlugin().getServer().getOnlinePlayers().values(), bpk);
}
示例10: sendData
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
public void sendData(Player player, EntityMetadata data) {
SetEntityDataPacket pk = new SetEntityDataPacket();
pk.entityRuntimeId = this.getId();
pk.metadata = data == null ? this.dataProperties : data;
player.dataPacket(pk);
}
示例11: setDataProperty
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
public boolean setDataProperty(EntityData data, boolean send) {
if (!Objects.equals(data, this.getDataProperties().get(data.getId()))) {
this.getDataProperties().put(data);
if (send)
this.sendData(this.hasSpawned.values().stream().toArray(Player[]::new), new EntityMetadata().put(this.dataProperties.get(data.getId())));
return true;
}
return false;
}
示例12: setDataProperty
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
@Override
public boolean setDataProperty(EntityData data, boolean send) {
if (super.setDataProperty(data, send)) {
if (send) this.sendData(this, new EntityMetadata().put(this.getDataProperty(data.getId())));
return true;
}
return false;
}
示例13: spawnTo
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
public void spawnTo(Player player){
if(!this.isSpawned(player) && this.canSee(player)){
this.viewers.put(player.getLoaderId(), player);
AddItemEntityPacket addItemEntityPk = new AddItemEntityPacket();
addItemEntityPk.eid = this.id;
addItemEntityPk.x = (float) this.x + 0.5f;
addItemEntityPk.y = (float) this.y;
addItemEntityPk.z = (float) this.z + 0.5f;
addItemEntityPk.speedX = 0;
addItemEntityPk.speedY = 0;
addItemEntityPk.speedZ = 0;
addItemEntityPk.item = this.getItem();
AddEntityPacket addEntityPk = new AddEntityPacket();
addEntityPk.type = 69;
addEntityPk.eid = this.riderId;
addEntityPk.x = addItemEntityPk.x;
addEntityPk.y = addItemEntityPk.y;
addEntityPk.z = addItemEntityPk.z;
addEntityPk.speedX = 0;
addEntityPk.speedY = 0;
addEntityPk.speedZ = 0;
EntityMetadata metadata = new EntityMetadata();
metadata.put(new ByteEntityData(Entity.DATA_NO_AI, 1));
if(ItemDisplay.getInstance().isNametagViewer(player)){
metadata.put(new ByteEntityData(Entity.DATA_SHOW_NAMETAG, 1));
metadata.put(new StringEntityData(Entity.DATA_NAMETAG, Translation.translate("showNametag.toViewer", new String[]{this.name, String.valueOf(this.item.getId()), String.valueOf(this.item.getDamage())})));
}
addEntityPk.metadata = metadata;
SetEntityLinkPacket setEntityLinkPk = new SetEntityLinkPacket();
setEntityLinkPk.rider = this.riderId;
setEntityLinkPk.riding = this.id;
setEntityLinkPk.type = 1;
player.dataPacket(addItemEntityPk);
player.dataPacket(addEntityPk);
player.dataPacket(setEntityLinkPk);
}
}
示例14: sendBossBar
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
/**
* Sends the text to one player
*
* @param Player players
* To who to send
* @param int eid
* The EID of an existing fake wither
* @param String title
* The title of the boss bar
* @param null|int ticks
* How long it displays
*/
public static void sendBossBar(Player player, int eid, String title){
if(title.equals("")){
return;
}
if(Main.getInstance().hide.containsKey(player.getName().toLowerCase())){
return;
}
AddEntityPacket packet = new AddEntityPacket();
packet.entityUniqueId = eid;
packet.entityRuntimeId = eid;
packet.type = 52;
packet.yaw = packet.pitch = 0;
long flags = 0;
flags |= 1 << Entity.DATA_FLAG_SILENT;
flags |= 1 << Entity.DATA_FLAG_INVISIBLE;
flags |= 1 << Entity.DATA_FLAG_NO_AI;
EntityMetadata dataProperties = new EntityMetadata()
.putLong(Entity.DATA_FLAGS, flags)
.putShort(Entity.DATA_AIR, 400)
.putShort(Entity.DATA_MAX_AIR, 400)
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
.putFloat(Entity.DATA_SCALE, 1f)
.putString(Entity.DATA_NAMETAG, title)
.putInt(Entity.DATA_SCALE, 0);
packet.metadata = dataProperties;
packet.x = (float) player.x;
packet.y = (float) (player.y - 28);
packet.z = (float) player.z;
player.dataPacket(packet);
BossEventPacket bpk = new BossEventPacket(); // This updates the bar
bpk.eid = eid;
bpk.type = 0;
player.dataPacket(bpk);
}
示例15: sendTitle
import cn.nukkit.entity.data.EntityMetadata; //导入依赖的package包/类
/**
* Sets the BossBar title by EID
*
* @param String title
* @param int eid
*/
public static void sendTitle(Player player, int eid, String title){
SetEntityDataPacket npk = new SetEntityDataPacket(); // change name of fake wither . bar text
long flags = 0;
flags |= 1 << Entity.DATA_FLAG_SILENT;
flags |= 1 << Entity.DATA_FLAG_INVISIBLE;
flags |= 1 << Entity.DATA_FLAG_NO_AI;
EntityMetadata dataProperties = new EntityMetadata()
.putLong(Entity.DATA_FLAGS, flags)
.putShort(Entity.DATA_AIR, 400)
.putShort(Entity.DATA_MAX_AIR, 400)
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
.putFloat(Entity.DATA_SCALE, 1f)
.putString(Entity.DATA_NAMETAG, title)
.putInt(Entity.DATA_SCALE, 0);
npk.metadata = dataProperties;
npk.eid = eid;
player.dataPacket(npk);
BossEventPacket bpk = new BossEventPacket(); // This updates the bar
bpk.eid = eid;
bpk.type = 1; // UPDATE
player.dataPacket(bpk);
}