Java Code Examples for cn.nukkit.Player#isCreative()
The following examples show how to use
cn.nukkit.Player#isCreative() .
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: BlockCommand.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean onActivate(Item item, Player player) { if (!(player.isOp() && player.isCreative())) { return false; } BlockEntityCommandBlock blockEntity = this.getBlockEntity(); if (blockEntity == null) { CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.COMMAND_BLOCK) .putInt("x", this.getFloorX()) .putInt("y", this.getFloorY()) .putInt("z", this.getFloorZ()) .putInt("commandBlockMode", this.getMode()); blockEntity = new BlockEntityCommandBlock(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt); } blockEntity.spawnTo(player); blockEntity.show(player); return true; }
Example 2
Source File: ItemFirework.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean onClickAir(Player player, Vector3 directionVector) { if (player.getInventory().getChestplate() instanceof ItemElytra && player.isGliding()) { this.spawnFirework(player.getLevel(), player); player.setMotion(new Vector3( -Math.sin(Math.toRadians(player.yaw)) * Math.cos(Math.toRadians(player.pitch)) * 2, -Math.sin(Math.toRadians(player.pitch)) * 2, Math.cos(Math.toRadians(player.yaw)) * Math.cos(Math.toRadians(player.pitch)) * 2)); if (!player.isCreative()) { this.count--; } return true; } return false; }
Example 3
Source File: MoreCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length != 0) { this.sendUsage(sender); return false; } Player player = (Player) sender; if (player.isCreative() || player.isSpectator()) { sender.sendMessage(TextFormat.RED + Language.translate("commands.more.notavalible")); return false; } Item item = player.getInventory().getItemInHand(); if (item.getId() == Item.AIR) { sender.sendMessage(TextFormat.RED + Language.translate("commands.more.air")); return false; } item.setCount(item.getMaxStackSize()); player.getInventory().setItemInHand(item); sender.sendMessage(Language.translate("commands.more.success")); return true; }
Example 4
Source File: BlockCommand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (!(player.isOp() && player.isCreative())) { return false; } int f = 0; if (player instanceof Player) { double pitch = player.getPitch(); if (Math.abs(pitch) >= 45) { if (pitch < 0) { f = 4; } else { f = 5; } } else { f = player.getDirection().getHorizontalIndex(); } } int[] faces = new int[]{4, 2, 5, 3, 0, 1}; this.meta = faces[f]; this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.COMMAND_BLOCK) .putInt("x", this.getFloorX()) .putInt("y", this.getFloorY()) .putInt("z", this.getFloorZ()) .putInt("commandBlockMode", this.getMode()); new BlockEntityCommandBlock(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt); return true; }
Example 5
Source File: ItemEdible.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onClickAir(Player player, Vector3 directionVector) { if (player.getFoodData().getLevel() < player.getFoodData().getMaxLevel() || player.isCreative()) { return true; } player.getFoodData().sendFoodLevel(); return false; }
Example 6
Source File: ItemFirework.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (block.canPassThrough()) { this.spawnFirework(level, block); if (!player.isCreative()) { player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); } return true; } return false; }
Example 7
Source File: BlockMagma.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void onEntityCollide(Entity entity) { if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { if (entity instanceof Player) { Player p = (Player) entity; if (!p.isCreative() && !p.isSpectator() && !p.isSneaking()) { entity.attack(new EntityDamageByBlockEvent(this, entity, EntityDamageEvent.DamageCause.LAVA, 1)); } } else { entity.attack(new EntityDamageByBlockEvent(this, entity, EntityDamageEvent.DamageCause.LAVA, 1)); } } }
Example 8
Source File: BlockTNT.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { if (item.getId() == Item.FLINT_STEEL) { item.useOn(this); this.prime(80, player); return true; } if (item.getId() == Item.FIRE_CHARGE) { if (!player.isCreative()) player.getInventory().removeItem(Item.get(Item.FIRE_CHARGE, 0, 1)); this.level.addSound(player, Sound.MOB_GHAST_FIREBALL); this.prime(80, player); return true; } return false; }
Example 9
Source File: CreativeInventoryAction.java From Jupiter with GNU General Public License v3.0 | 4 votes |
/** * Checks that the player is in creative, and (if creating an item) that the item exists in the creative inventory. */ public boolean isValid(Player source) { return source.isCreative() && (this.actionType == TYPE_DELETE_ITEM || Item.getCreativeItemIndex(this.sourceItem) != -1); }
Example 10
Source File: ItemBow.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onClickAir(Player player, Vector3 directionVector) { return player.getInventory().contains(Item.get(ItemID.ARROW)) || player.isCreative(); }
Example 11
Source File: ProjectileItem.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight() - 0.30000000149011612)) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { if (projectile instanceof EntityEnderPearl) { if (player.getServer().getTick() - player.getLastEnderPearlThrowingTick() < 20) { projectile.kill(); return false; } } projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { if (!player.isCreative()) { this.count--; } if (projectile instanceof EntityEnderPearl) { player.onThrowEnderPearl(); } projectile.spawnToAll(); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_BOW); } } } else { return false; } return true; }
Example 12
Source File: ItemTrident.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onRelease(Player player, int ticksUsed) { this.useOn(player); CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw)) .add(new FloatTag("", (float) -player.pitch))); double p = (double) ticksUsed / 20; double f = Math.min((p * p + p * 2) / 3, 1) * 2; EntityThrownTrident trident = (EntityThrownTrident) Entity.createEntity("ThrownTrident", player.chunk, nbt, player, f == 2); if (trident == null) { return false; } trident.setItem(this); EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, trident, f); if (f < 0.1 || ticksUsed < 5) { entityShootBowEvent.setCancelled(); } Server.getInstance().getPluginManager().callEvent(entityShootBowEvent); if (entityShootBowEvent.isCancelled()) { entityShootBowEvent.getProjectile().kill(); } else { entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce())); if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile()); Server.getInstance().getPluginManager().callEvent(ev); if (ev.isCancelled()) { entityShootBowEvent.getProjectile().kill(); } else { entityShootBowEvent.getProjectile().spawnToAll(); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_ITEM_TRIDENT_THROW); if (!player.isCreative()) { this.count--; player.getInventory().setItemInHand(this); } } } } return true; }
Example 13
Source File: CreativeInventoryAction.java From Nukkit with GNU General Public License v3.0 | 4 votes |
/** * Checks that the player is in creative, and (if creating an item) that the item exists in the creative inventory. */ public boolean isValid(Player source) { return source.isCreative() && (this.actionType == TYPE_DELETE_ITEM || Item.getCreativeItemIndex(this.sourceItem) != -1); }
Example 14
Source File: CreativeInventoryAction.java From Nukkit with GNU General Public License v3.0 | 2 votes |
/** * Checks that the player is in creative, and (if creating an item) that the item exists in the creative inventory. * * @param source player * @return valid */ public boolean isValid(Player source) { return source.isCreative() && (this.actionType == TYPE_DELETE_ITEM || Item.getCreativeItemIndex(this.sourceItem) != -1); }