@Override public Location getLocation() { org.spongepowered.api.world.Location<World> entityLoc = this.player.getLocation(); Vector3d entityRot = this.player.getRotation(); return SpongeWorldEdit.inst().getAdapter().adapt(entityLoc, entityRot); }
/** * Helper method for formatting player container data. * * @param player */ private void writePlayerLocation(Player player) { checkNotNull(player); data.set(DataQueries.Target, player.getName()); data.set(DataQueries.Location, player.getLocation().toContainer()); } }
@Override public Optional<Pair<String, String>> processDefault(QuerySession session, Query query) { if (session.getCommandSource() instanceof Player) { // Default radius from config int defaultRadius = Prism.getInstance().getConfiguration().getNode("defaults", "radius").getInt(); // Player location Location<World> location = ((Player) session.getCommandSource()).getLocation(); query.addCondition(ConditionGroup.from(location, defaultRadius)); session.setRadius(defaultRadius); return Optional.of(Pair.of(aliases.get(0), "" + defaultRadius)); } return Optional.empty(); } }
@Override protected final void powder(final SnipeData v) { Player player = v.owner().getPlayer(); strikeLightning(player.getLocation(), player); player.setLocation(this.lastBlock); strikeLightning(this.lastBlock, player); }
public void protect(Player player) { SubjectData subjectData = player.getTransientSubjectData(); Map<Set<Context>, Map<String, Boolean>> permissions = Collections.emptyMap(); if (config.getGeneral().isProtectPermissions()) { permissions = subjectData.getAllPermissions(); subjectData.clearPermissions(); } protections.put(player.getUniqueId(), new ProtectionData(player.getLocation(), permissions)); TeleportConfig teleportConfig = config.getGeneral().getTeleport(); if (teleportConfig.isEnabled()) { teleportConfig.getSpawnLocation().ifPresent(worldLocation -> safeTeleport(player, worldLocation)); } else { Location<World> oldLoc = player.getLocation(); //sometimes players stuck in a wall safeTeleport(player, oldLoc); } }
@Override public void run () { if(minecart.isRemoved()) return; if(giveItem.getValue() && player.gameMode().get() != GameModes.CREATIVE) { ItemStack stack = ItemStack.of(ItemTypes.MINECART, 1); if(!((Player) player).getInventory().offer(stack).getRejectedItems().isEmpty()) { Item item = (Item) player.getLocation().getExtent().createEntity(EntityTypes.ITEM, player.getLocation().getPosition().add(0, 1, 0)); item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot()); player.getLocation().getExtent().spawnEntity(item); } } minecart.remove(); } }
public CachedPlayer(Player player) { super(player); this.uuid = UUID.fromString(player.getUniqueId().toString()); this.name = player.getName(); this.isOnline = true; this.location = new CachedLocation(player.getLocation()); this.rotation = player.getRotation().clone(); this.velocity = player.getVelocity().clone(); this.scale = player.getScale().clone(); this.address = player.getConnection().getAddress().toString(); this.latency = player.getConnection().getLatency(); // Collect unlocked advancements for (AdvancementTree tree : player.getUnlockedAdvancementTrees()) { addUnlockedAdvancements(player, tree.getRootAdvancement()); } // This will be moved to the other constructor once Sponge implements the offline inventory API this.helmet = player.getHelmet().map(ItemStack::copy).orElse(null); this.chestplate = player.getChestplate().map(ItemStack::copy).orElse(null); this.leggings = player.getLeggings().map(ItemStack::copy).orElse(null); this.boots = player.getBoots().map(ItemStack::copy).orElse(null); this.inventory = new CachedInventory(player.getInventory()); }
@Override public void run () { if(boat.isRemoved()) return; if(giveItem.getValue()) { ItemType boatType = ItemTypes.BOAT; TreeType treeType = boat.get(Keys.TREE_TYPE).orElse(TreeTypes.OAK); if (treeType == TreeTypes.OAK) { boatType = ItemTypes.BOAT; } else if (treeType == TreeTypes.ACACIA) { boatType = ItemTypes.ACACIA_BOAT; } else if (treeType == TreeTypes.BIRCH) { boatType = ItemTypes.BIRCH_BOAT; } else if (treeType == TreeTypes.DARK_OAK) { boatType = ItemTypes.DARK_OAK_BOAT; } else if (treeType == TreeTypes.JUNGLE) { boatType = ItemTypes.JUNGLE_BOAT; } else if (treeType == TreeTypes.SPRUCE) { boatType = ItemTypes.SPRUCE_BOAT; } ItemStack stack = ItemStack.of(boatType, 1); if(!((Player) player).getInventory().offer(stack).getRejectedItems().isEmpty()) { Item item = (Item) player.getLocation().getExtent().createEntity(EntityTypes.ITEM, player.getLocation().getPosition().add(0, 1, 0)); item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot()); player.getLocation().getExtent().spawnEntity(item); } } boat.remove(); } }
@Override public Optional<CompletableFuture<?>> process(QuerySession session, String parameter, String value, Query query) { if (session.getCommandSource() instanceof Player) { Player player = (Player) session.getCommandSource(); Location<World> location = player.getLocation(); int radius = Integer.parseInt(value); int maxRadius = Prism.getInstance().getConfiguration().getNode("limits", "radius", "max").getInt(); // Enforce max radius unless player has override perms if (radius > maxRadius && !player.hasPermission("prism.override.radius")) { // @todo move this player.sendMessage(Format.subduedHeading(String.format("Limiting radius to maximum of %d", maxRadius))); radius = maxRadius; } session.setRadius(radius); query.addCondition(ConditionGroup.from(location, radius)); } return Optional.empty(); }
@Override public void play(Note note) { if(!isPlaying()) return; Sponge.getServer().getPlayer(getPlayer()).ifPresent(player -> player.playSound(toSound(note.getInstrument()), player.getLocation().getPosition(), note.getVelocity(), note.getNote())); }
@Override public void teleport(Location location) { if ((Math.abs(location.getX()) >= 30000000) || (Math.abs(location.getZ()) >= 30000000)) { return; } String world = this.player.getWorld().getName(); if (!world.equals(location.getWorld())) { this.player.transferToWorld(location.getWorld(), new Vector3d(location.getX(), location.getY(), location.getZ())); } else { org.spongepowered.api.world.Location<World> current = this.player.getLocation(); current = current.setPosition(new Vector3d(location.getX(), location.getY(), location.getZ())); this.player.setLocation(current); } }
private void doFireball(final SnipeData v) { Player pl = v.owner().getPlayer(); Vector3d target = this.targetBlock.getPosition().sub(pl.getLocation().getPosition().add(0, 1.72, 0)); pl.launchProjectile(SmallFireball.class, target.normalize()); }
private void doLargeFireball(final SnipeData v) { Player pl = v.owner().getPlayer(); Vector3d target = this.targetBlock.getPosition().sub(pl.getLocation().getPosition().add(0, 1.72, 0)); pl.launchProjectile(LargeFireball.class, target.normalize()); }
public static CommandSpec getCommand() { return CommandSpec.builder() .permission("prism.extinguish") .arguments(GenericArguments.integer(Text.of("radius"))) .executor((source, args) -> { if (!(source instanceof Player)) { throw new CommandException(Format.error("You must be a player to use this command.")); } int radius = args.<Integer>getOne("radius").get(); int changes = WorldUtil.removeAroundFromLocation( BlockTypes.FIRE, ((Player) source).getLocation(), radius); source.sendMessage(Format.message(String.format("Removed %d matches within %d blocks", changes, radius))); return CommandResult.success(); }) .build(); } }
private void spawnFireball(Player player, boolean isLarge) { World world = player.getWorld(); Vector3d playerRot = player.getRotation(); Vector3d playerLoc = player.getLocation().getPosition(); Vector3d spawnLoc = playerLoc.add(Math.cos((playerRot.getY() - 90) % 360) * 0.2, 1.8, Math.sin((playerRot.getY() - 90) % 360) * 0.2);
private void sendUpdateSelf() { receiver.getTabList().removeEntry(receiver.getUniqueId()); receiver.getTabList().addEntry(TabListEntry.builder() .displayName(receiver.getDisplayNameData().displayName().get()) .latency(receiver.getConnection().getLatency()) .list(receiver.getTabList()) .gameMode(receiver.getGameModeData().type().get()) .profile(receiver.getProfile()) .build()); Location<World> oldLocation = receiver.getLocation(); Vector3d rotation = receiver.getRotation(); World receiverWorld = receiver.getWorld(); Sponge.getServer().getWorlds() .stream() .filter(world -> !world.equals(receiverWorld)) .findFirst() .ifPresent(world -> { receiver.setLocation(world.getSpawnLocation()); receiver.setLocationAndRotation(oldLocation, rotation); }); } }
((Player) source).getLocation(), session.getRadius()); changes += WorldUtil.removeItemEntitiesAroundLocation(((Player) source).getLocation(), session.getRadius()); ((Player) source).getLocation(), session.getRadius());
spawnCoordinates = player.getLocation().getBlockPosition();
private void addChair(Player player, Location<World> location) { Entity entity = location.getExtent().createEntity(EntityTypes.ARMOR_STAND, location.getBlockPosition().toDouble().sub(-0.5, 1.2, -0.5)); entity.offer(Keys.INVISIBLE, true); entity.offer(Keys.HAS_GRAVITY, false); if (faceCorrectDirection.getValue() && location.supports(Keys.DIRECTION)) { Vector3d euler = LocationUtil.cartesianToEuler(location.get(Keys.DIRECTION).orElse(Direction.NONE).getOpposite().asOffset()); entity.setRotation(euler); player.setRotation(euler); } Sponge.getCauseStackManager().pushCause(player); location.getExtent().spawnEntity(entity); Sponge.getCauseStackManager().popCause(); Chair<?> chair = new Chair<>((ArmorStand) entity, location, player.getLocation()); entity.addPassenger(player); player.sendMessage(Text.of(TextColors.YELLOW, "You sit down!")); chairs.put(player.getUniqueId(), chair); }
public static CommandSpec getCommand() { return CommandSpec.builder() .description(Text.of("Alias of /pr l r:(default radius)")) .permission("prism.lookup") .executor((source, args) -> { int radius = Prism.getInstance().getConfiguration().getNode("commands", "near", "defaultRadius").getInt(); source.sendMessage(Format.heading("Querying records...")); // Create a new query session final QuerySession session = new QuerySession(source); session.newQuery().addCondition(ConditionGroup.from(((Player) source).getLocation(), radius)); // Pass off to an async lookup helper AsyncUtil.lookup(session); return CommandResult.success(); }).build(); } }