cn.nukkit.Player Java Examples
The following examples show how to use
cn.nukkit.Player.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockWood.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { short[] faces = new short[]{ 0, 0, 0b1000, 0b1000, 0b0100, 0b0100 }; this.meta = ((this.meta & 0x03) | faces[face.getIndex()]); this.getLevel().setBlock(block, this, true, true); return true; }
Example #2
Source File: BlockCactus.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { Block down = this.down(); if (down.getId() == SAND || down.getId() == CACTUS) { Block block0 = north(); Block block1 = south(); Block block2 = west(); Block block3 = east(); if (block0.isTransparent() && block1.isTransparent() && block2.isTransparent() && block3.isTransparent()) { this.getLevel().setBlock(this, this, true); return true; } } return false; }
Example #3
Source File: EntityBlaze.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); }
Example #4
Source File: BlockCocoa.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean onActivate(Item item, Player player) { if (item.getId() == Item.DYE && item.getDamage() == 0x0f) { Block block = this.clone(); if (this.getDamage() / 4 < 2) { block.setDamage(block.getDamage() + 4); BlockGrowEvent ev = new BlockGrowEvent(this, block); Server.getInstance().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } this.getLevel().setBlock(this, ev.getNewState(), true, true); this.level.addParticle(new BoneMealParticle(this)); if (player != null && (player.gamemode & 0x01) == 0) { item.count--; } } return true; } return false; }
Example #5
Source File: EntityEnderDragon.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); }
Example #6
Source File: EntitySkeleton.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); MobEquipmentPacket pk1 = new MobEquipmentPacket(); pk1.eid = this.getId(); pk1.item = new ItemBow(); pk1.hotbarSlot = 10; player.dataPacket(pk1); super.spawnTo(player); }
Example #7
Source File: EntityGhast.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); }
Example #8
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void fall(float fallDistance) { float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0)); if (damage > 0) { this.attack(new EntityDamageEvent(this, DamageCause.FALL, damage)); } if (fallDistance > 0.75) { BlockVector3 v = new BlockVector3(getFloorX(), getFloorY() - 1, getFloorZ()); int down = this.level.getBlockIdAt(v.x, v.y, v.z); if (down == Item.FARMLAND) { if (this instanceof Player) { Player p = (Player) this; PlayerInteractEvent ev = new PlayerInteractEvent(p, p.getInventory().getItemInHand(), this.temporalVector.setComponents(v.x, v.y, v.z), null, Action.PHYSICAL); this.server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return; } } this.level.setBlock(this.temporalVector.setComponents(v.x, v.y, v.z), new BlockDirt(), true, true); } } }
Example #9
Source File: EntityVillager.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public void spawnTo(Player player) { if (!this.hasSpawned.containsKey(player.getLoaderId())) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
Example #10
Source File: BlockTorch.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { Block below = this.down(); if (!target.isTransparent() && face != BlockFace.DOWN) { int[] faces = new int[]{ 0, //0, nerver used 5, //1 4, //2 3, //3 2, //4 1, //5 }; this.setDamage(faces[face.getIndex()]); this.getLevel().setBlock(block, this, true, true); return true; } else if (!below.isTransparent() || below instanceof BlockFence || below.getId() == COBBLE_WALL) { this.setDamage(0); this.getLevel().setBlock(block, this, true, true); return true; } return false; }
Example #11
Source File: ContainerInventory.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void onOpen(Player who) { super.onOpen(who); ContainerOpenPacket pk = new ContainerOpenPacket(); pk.windowId = who.getWindowId(this); pk.type = this.getType().getNetworkType(); InventoryHolder holder = this.getHolder(); if (holder instanceof Vector3) { pk.x = (int) ((Vector3) holder).getX(); pk.y = (int) ((Vector3) holder).getY(); pk.z = (int) ((Vector3) holder).getZ(); } else { pk.x = pk.y = pk.z = 0; } who.dataPacket(pk); this.sendContents(who); }
Example #12
Source File: EntityEnderDragon.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); }
Example #13
Source File: BlockConcretePowder.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block b, Block target, BlockFace face, double fx, double fy, double fz, Player player) { boolean concrete = false; for (int side = 1; side <= 5; side++) { Block block = this.getSide(BlockFace.fromIndex(side)); if (block.getId() == Block.WATER || block.getId() == Block.STILL_WATER || block.getId() == Block.LAVA || block.getId() == Block.STILL_LAVA) { concrete = true; break; } } if (concrete) { this.level.setBlock(this, Block.get(Block.CONCRETE, this.getDamage()), true, true); } else { this.level.setBlock(this, this, true, true); } return true; }
Example #14
Source File: ListCommand.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } String online = ""; int onlineCount = 0; for (Player player : sender.getServer().getOnlinePlayers().values()) { if (player.isOnline() && (!(sender instanceof Player) || ((Player) sender).canSee(player))) { online += player.getDisplayName() + ", "; ++onlineCount; } } if (online.length() > 0) { online = online.substring(0, online.length() - 2); } sender.sendMessage(new TranslationContainer("commands.players.list", new String[]{String.valueOf(onlineCount), String.valueOf(sender.getServer().getMaxPlayers())})); sender.sendMessage(online); return true; }
Example #15
Source File: ContainerInventory.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void onClose(Player who) { ContainerClosePacket pk = new ContainerClosePacket(); pk.windowId = who.getWindowId(this); who.dataPacket(pk); super.onClose(who); }
Example #16
Source File: NukkitCommandSender.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public NukkitCommandSender(NukkitWorldEdit plugin, CommandSender sender) { checkNotNull(plugin); checkNotNull(sender); checkArgument(!(sender instanceof Player), "Cannot wrap a player"); this.plugin = plugin; this.sender = sender; }
Example #17
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public void spawnToAll() { if (this.chunk == null || this.closed) { return; } for (Player player : this.level.getChunkPlayers(this.chunk.getX(), this.chunk.getZ()).values()) { if (player.isOnline()) { this.spawnTo(player); } } }
Example #18
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 5 votes |
private LPSubscriptionValueSet(String permission, Set<Permissible> content) { this.permission = permission; this.backing = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>())); if (content != null) { this.backing.addAll(content); } // remove all players from the map this.backing.removeIf(p -> p instanceof Player); }
Example #19
Source File: ReplyNPC.java From FNPC-Nukkit with Do What The F*ck You Want To Public License | 5 votes |
@Override public void onTouch(Player player) { Object[] arr=this.chat.toArray(); if(arr.length>0) { player.sendMessage("<"+this.nametag+"> "+arr[new Random().nextInt(arr.length)]); } }
Example #20
Source File: RakNetInterface.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void notifyACK(String identifier, int identifierACK) { // TODO: Better ACK notification implementation! for (Player p : server.getOnlinePlayers().values()) { p.notifyACK(identifierACK); } }
Example #21
Source File: BlockDropper.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { if (player != null) { BlockEntity t = getLevel().getBlockEntity(this); BlockEntityDropper dropper; if (t instanceof BlockEntityDropper) { dropper = (BlockEntityDropper) t; } else { CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.DROPPER) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); dropper = new BlockEntityDropper(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt); } if (dropper.namedTag.contains("Lock") && dropper.namedTag.get("Lock") instanceof StringTag) { if (!dropper.namedTag.getString("Lock").equals(item.getCustomName())) { return false; } } player.addWindow(dropper.getInventory()); } return true; }
Example #22
Source File: EntityAnimal.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onInteract(Player player, Item item, Vector3 clickedPos) { if (item.getId() == Item.NAME_TAG) { if (item.hasCustomName()) { this.setNameTag(item.getCustomName()); this.setNameTagVisible(true); player.getInventory().removeItem(item); return true; } } return false; }
Example #23
Source File: FaweNukkit.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); FawePlayer fp = Fawe.get().getCachedPlayer(player.getName()); if (fp != null) { fp.unregister(); } Fawe.get().unregister(event.getPlayer().getName()); }
Example #24
Source File: EntityPainting.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void spawnTo(Player player) { AddPaintingPacket pk = new AddPaintingPacket(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (int) this.x; pk.y = (int) this.y; pk.z = (int) this.z; pk.direction = this.getDirection().getHorizontalIndex(); pk.title = this.namedTag.getString("Motive"); player.dataPacket(pk); super.spawnTo(player); }
Example #25
Source File: BlockItemFrame.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity; if (itemFrame.getItem().getId() == Item.AIR) { // We can't use Item.get(item.getId(), item.getDamage(), 1) because // we need to keep the item's NBT tags Item itemOnFrame = item.clone(); // So we clone the item itemOnFrame.setCount(1); // Change it to only one item (if we keep +1, visual glitches will happen) itemFrame.setItem(itemOnFrame); // And then we set it on the item frame // The item will be removed from the player's hand a few lines ahead this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ADD_ITEM); if (player != null && player.isSurvival()) { int count = item.getCount(); if (count-- <= 0) { player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0)); return true; } item.setCount(count); player.getInventory().setItemInHand(item); } } else { int itemRot = itemFrame.getItemRotation(); if (itemRot >= 7) { itemRot = 0; } else { itemRot++; } itemFrame.setItemRotation(itemRot); this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ROTATE_ITEM); } return true; }
Example #26
Source File: BlockTrapdoor.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { if (!this.toggle(player)) { return false; } this.getLevel().setBlock(this, this, true); this.level.addSound(new DoorSound(this)); return true; }
Example #27
Source File: EntityBoat.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onInteract(Player player, Item item) { if (this.linkedEntity != null) { return false; } super.mountEntity(player); return true; }
Example #28
Source File: BlockCake.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { if (player != null && player.getFoodData().getLevel() < player.getFoodData().getMaxLevel()) { if (getDamage() <= 0x06) setDamage(getDamage() + 1); if (getDamage() >= 0x06) { getLevel().setBlock(this, new BlockAir(), true); } else { Food.getByRelative(this).eatenBy(player); getLevel().setBlock(this, this, true); } return true; } return false; }
Example #29
Source File: EventListener.java From EssentialsNK with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerChat(PlayerChatEvent event) { Player player = event.getPlayer(); if (api.isMuted(player)) { event.setCancelled(); player.sendMessage(Language.translate("commands.generic.muted", api.getUnmuteTimeMessage(player))); } }
Example #30
Source File: EntityHuman.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected void initEntity() { this.setDataFlag(DATA_PLAYER_FLAGS, DATA_PLAYER_FLAG_SLEEP, false); this.setDataFlag(DATA_FLAGS, DATA_FLAG_GRAVITY); this.setDataProperty(new IntPositionEntityData(DATA_PLAYER_BED_POSITION, 0, 0, 0), false); if (!(this instanceof Player)) { if (this.namedTag.contains("NameTag")) { this.setNameTag(this.namedTag.getString("NameTag")); } if (this.namedTag.contains("Skin") && this.namedTag.get("Skin") instanceof CompoundTag) { if (!this.namedTag.getCompound("Skin").contains("Transparent")) { this.namedTag.getCompound("Skin").putBoolean("Transparent", false); } this.setSkin(new Skin( this.namedTag.getCompound("Skin").getString("skinId"), this.namedTag.getCompound("Skin").getByteArray("skinData"), this.namedTag.getCompound("Skin").getCompound("capeData").getByteArray("capeData"), this.namedTag.getCompound("Skin").getString("geometryName"), this.namedTag.getCompound("Skin").getCompound("geometryData").getString("geometryData") )); } this.uuid = Utils.dataToUUID(String.valueOf(this.getId()).getBytes(StandardCharsets.UTF_8), this.getSkin() .getSkinData(), this.getNameTag().getBytes(StandardCharsets.UTF_8)); } super.initEntity(); if (this instanceof Player) { ((Player) this).addWindow(this.inventory, 0); } }