Java Code Examples for org.spongepowered.api.entity.living.player.Player#setTransform()

The following examples show how to use org.spongepowered.api.entity.living.player.Player#setTransform() . 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: UnJailExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Player target = ctx.<Player> getOne("target").get();
	Transform<World> spawn = Utils.getSpawn();

	if (EssentialCmds.jailedPlayers.contains(target.getUniqueId()))
	{
		if (spawn != null)
		{
			if (!Objects.equals(target.getWorld().getUniqueId(), spawn.getExtent().getUniqueId()))
			{
				target.transferToWorld(spawn.getExtent().getUniqueId(), spawn.getPosition());
				target.setTransform(spawn);
			}
			else
			{
				target.setTransform(spawn);
			}
		}
		else
		{
			target.setLocation(target.getWorld().getSpawnLocation());
		}
		
		src.sendMessage(Text.of(TextColors.GREEN, "You have been unjailed."));
		EssentialCmds.jailedPlayers.remove(target.getUniqueId());
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Un-jailed player."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Player is not jailed."));
	}

	return CommandResult.success();
}
 
Example 2
Source File: SpawnExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Transform<World> spawn = Utils.getSpawn();

		if (Utils.isSpawnInConfig())
		{
			if (Utils.isTeleportCooldownEnabled() && !player.hasPermission("essentialcmds.teleport.cooldown.override"))
			{
				EssentialCmds.teleportingPlayers.add(player.getUniqueId());
				src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleporting to Spawn. Please wait " + Utils.getTeleportCooldown() + " seconds."));

				Sponge.getScheduler().createTaskBuilder().execute(() -> {
					if (EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
					{
						Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

						if (!Objects.equals(player.getWorld().getUniqueId(), spawn.getExtent().getUniqueId()))
						{
							player.transferToWorld(spawn.getExtent().getUniqueId(), spawn.getPosition());
							player.setTransform(spawn);
						}
						else
						{
							player.setTransform(spawn);
						}

						src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to Spawn"));
						EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
					}
				}).delay(Utils.getTeleportCooldown(), TimeUnit.SECONDS).name("EssentialCmds - Back Timer").submit(Sponge.getGame().getPluginManager().getPlugin(PluginInfo.ID).get().getInstance().get());
			}
			else
			{
				Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

				if (!Objects.equals(player.getWorld().getUniqueId(), spawn.getExtent().getUniqueId()))
				{
					player.transferToWorld(spawn.getExtent().getUniqueId(), spawn.getPosition());
					player.setTransform(spawn);
				}
				else
				{
					player.setTransform(spawn);
				}

				src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to Spawn"));
			}
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Spawn has not been set yet!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /spawn!"));
	}

	return CommandResult.success();
}
 
Example 3
Source File: HomeExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	String homeName = ctx.<String> getOne("home name").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (Utils.isHomeInConfig(player.getUniqueId(), homeName))
		{
			try
			{
				if (Utils.isTeleportCooldownEnabled() && !player.hasPermission("essentialcmds.teleport.cooldown.override"))
				{
					EssentialCmds.teleportingPlayers.add(player.getUniqueId());
					src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleporting to home " + Utils.getConfigHomeName(player.getUniqueId(), homeName) + ". Please wait " + Utils.getTeleportCooldown() + " seconds."));

					Sponge.getScheduler().createTaskBuilder().execute(() -> {
						if (EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
						{
							Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

							if (Objects.equals(player.getWorld().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId()))
							{
								player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
							}
							else
							{
								player.transferToWorld(Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getPosition());
								player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
							}

							src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to home " + Utils.getConfigHomeName(player.getUniqueId(), homeName)));
							EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
						}
					}).delay(Utils.getTeleportCooldown(), TimeUnit.SECONDS).name("EssentialCmds - Back Timer").submit(Sponge.getGame().getPluginManager().getPlugin(PluginInfo.ID).get().getInstance().get());
				}
				else
				{
					Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

					if (Objects.equals(player.getWorld().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId()))
					{
						player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
					}
					else
					{
						player.transferToWorld(Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getPosition());
						player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
					}

					src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to home " + Utils.getConfigHomeName(player.getUniqueId(), homeName)));
				}
			}
			catch (PositionOutOfBoundsException e)
			{
				src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Home is in invalid coordinates!"));
			}
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must first set your home!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /home!"));
	}

	return CommandResult.success();
}