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

The following examples show how to use org.spongepowered.api.entity.living.player.Player#setLocation() . 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: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
private static void tpWait(final Player p, final Location<World> loc, final String rname) {
    if (p.hasPermission("redprotect.command.admin.teleport")) {
        p.setLocation(loc);
        return;
    }
    if (!RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.add(p.getName());
        RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpdontmove");
        Sponge.getScheduler().createSyncExecutor(RedProtect.get().container).schedule(() -> {
            if (RedProtect.get().tpWait.contains(p.getName())) {
                RedProtect.get().tpWait.remove(p.getName());
                p.setLocation(loc);
                RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("cmdmanager.region.teleport") + " " + rname);
            }
        }, RedProtect.get().config.configRoot().region_settings.teleport_time, TimeUnit.SECONDS);
    } else {
        RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpneedwait");
    }
}
 
Example 2
Source File: Utils.java    From EssentialCmds with MIT License 6 votes vote down vote up
public static void teleportPlayerToJail(Player player, int number)
{
	UUID worldUuid = UUID.fromString(Configs.getConfig(jailsConfig).getNode("jails", String.valueOf(number), "world").getString());
	double x = Configs.getConfig(jailsConfig).getNode("jails", String.valueOf(number), "X").getDouble();
	double y = Configs.getConfig(jailsConfig).getNode("jails", String.valueOf(number), "Y").getDouble();
	double z = Configs.getConfig(jailsConfig).getNode("jails", String.valueOf(number), "Z").getDouble();
	World world = Sponge.getServer().getWorld(worldUuid).orElse(null);

	if (world != null)
	{
		Location<World> location = new Location<World>(world, x, y, z);

		if (player.getWorld().getUniqueId().equals(worldUuid))
		{
			player.setLocation(location);
		}
		else
		{
			player.transferToWorld(world.getUniqueId(), location.getPosition());
		}
	}
}
 
Example 3
Source File: WorldsBase.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Vector3i spawnPos = player.getWorld().getProperties().getSpawnPosition();
		player.setLocation(new Location<>(player.getWorld(), spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()));
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to world spawn."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport, you are not a player!"));
	}

	return CommandResult.success();
}
 
Example 4
Source File: TPChunkExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	int x = ctx.<Integer> getOne("x").get();
	int z = ctx.<Integer> getOne("z").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;
		Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

		if (Sponge.getServer().getChunkLayout().isValidChunk(new Vector3i(x, 0, z)))
		{
			Location<World> location = new Location<World>(player.getWorld(), Sponge.getServer().getChunkLayout().forceToWorld(new Vector3i(x, 0, z)));
			player.setLocation(location);
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to chunk."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Invalid chunk!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport, you are not a player!"));
	}

	return CommandResult.success();
}
 
Example 5
Source File: CommandClaimSpawn.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    if (!playerData.canIgnoreClaim(claim) && !claim.isUserTrusted(player, TrustType.ACCESSOR) && !player.hasPermission(GPPermissions.COMMAND_DELETE_CLAIMS)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionAccess.toText());
        return CommandResult.success();
    }

    final Vector3i spawnPos = claim.getData().getSpawnPos().orElse(null);
    if (spawnPos == null) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.commandSpawnNotSet.toText());
        return CommandResult.success();
    }

    final Location<World> spawnLocation = new Location<World>(claim.getWorld(), spawnPos);
    player.setLocation(spawnLocation);
    final Text message = GriefPreventionPlugin.instance.messageData.commandSpawnTeleport
            .apply(ImmutableMap.of(
            "location", spawnPos)).build();
    GriefPreventionPlugin.sendMessage(src, message);

    return CommandResult.success();
}
 
Example 6
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 7
Source File: TPHereExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Player recipient = ctx.<Player> getOne("player").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;
		if (recipient == player)
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport to yourself!"));
		}
		else
		{
			player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.WHITE, recipient.getName() + " has been teleported to your location!"));
			recipient.sendMessage(Text.of(TextColors.GREEN, player.getName(), TextColors.WHITE, " has teleported you to their location!"));
			recipient.setLocation(player.getLocation());
		}

	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tphere!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tphere!"));
	}
	
	return CommandResult.success();
}
 
Example 8
Source File: TPAllExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		for (Player p : Sponge.getServer().getOnlinePlayers())
		{
			Utils.setLastTeleportOrDeathLocation(p.getUniqueId(), p.getLocation());

			if (p.getWorld().getUniqueId() != player.getWorld().getUniqueId())
			{
				p.transferToWorld(player.getWorld().getUniqueId(), player.getLocation().getPosition());
			}
			else
			{
				p.setLocation(player.getLocation());
			}

			p.sendMessage(Text.of(TextColors.GREEN, "You were teleported to ", TextColors.YELLOW, player.getName()));
		}

		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported all players to you."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpall!"));
	}
}
 
Example 9
Source File: TeleportPosExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Optional<Player> p = ctx.<Player> getOne("player");
	World world = null;
	if (ctx.hasAny("world")) {
		Optional<WorldProperties> optionalWorldProperties = ctx.<WorldProperties> getOne("world");
		WorldProperties worldProperties = optionalWorldProperties.orElse(null);
		if (worldProperties != null) {
			// check if world is loaded
			Optional<World> optionalWorld = Sponge.getServer().getWorld(worldProperties.getUniqueId());
			world = optionalWorld.orElse(null);
			if (world == null) {
				// attempt to load world
				world = Sponge.getServer().loadWorld(worldProperties).orElse(null);
				if (world == null) {
					src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not load world " + worldProperties.getWorldName() + "."));
					return CommandResult.success();
				}
			}
		}
	} else {
		if (p.isPresent()) {
			world = p.get().getWorld();
		} else if (src instanceof Player) {
			world = ((Player) src).getWorld();
		} else {
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No valid world could be found!"));
			return CommandResult.success();
		}
	}

	int x = ctx.<Integer> getOne("x").get();
	int y = ctx.<Integer> getOne("y").get();
	int z = ctx.<Integer> getOne("z").get();

	if (p.isPresent())
	{
		if (src.hasPermission("teleport.pos.others"))
		{
			Utils.setLastTeleportOrDeathLocation(p.get().getUniqueId(), p.get().getLocation());
			p.get().setLocation(new Location<>(world, x, y, z));
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported player " + p.get().getName() + " to " + x + "," + y + "," + z + "."));
			p.get().sendMessage(Text.of(TextColors.GOLD, "You have been teleported by " + src.getName()));
		}
	}
	else
	{
		if (src instanceof Player)
		{
			Player player = (Player) src;
			Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());
			player.setLocation(new Location<>(world, x, y, z));
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to coords."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport, you are not a player!"));
		}
	}

	return CommandResult.success();
}
 
Example 10
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handletp(CommandSource source, String rname, World world, Player play) {
    Region region = RedProtect.get().rm.getRegion(rname, world.getName());
    if (region == null) {
        RedProtect.get().lang.sendMessage(source, RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + rname);
        return;
    }

    if (play == null) {
        if (source instanceof Player && !RedProtect.get().ph.hasRegionPermMember((Player) source, "teleport", region)) {
            RedProtect.get().lang.sendMessage(source, "no.permission");
            return;
        }
    } else {
        if (!RedProtect.get().ph.hasPerm(source, "redprotect.command.admin.teleport")) {
            RedProtect.get().lang.sendMessage(source, "no.permission");
            return;
        }
    }

    Location<World> loc = null;
    if (region.getTPPoint() != null) {
        loc = new Location<>(world, region.getTPPoint().getBlockX() + 0.500, region.getTPPoint().getBlockY(), region.getTPPoint().getBlockZ() + 0.500);
    } else {
        int limit = world.getBlockMax().getY();
        if (world.getDimension().getType().equals(DimensionTypes.NETHER)) {
            limit = 124;
        }
        for (int i = limit; i > 0; i--) {
            BlockType mat = world.createSnapshot(region.getCenterX(), i, region.getCenterZ()).getState().getType();
            BlockType mat1 = world.createSnapshot(region.getCenterX(), i + 1, region.getCenterZ()).getState().getType();
            BlockType mat2 = world.createSnapshot(region.getCenterX(), i + 2, region.getCenterZ()).getState().getType();
            if (!mat.equals(BlockTypes.LAVA) && !mat.equals(BlockTypes.AIR) && mat1.equals(BlockTypes.AIR) && mat2.equals(BlockTypes.AIR)) {
                loc = new Location<>(world, region.getCenterX() + 0.500, i + 1, region.getCenterZ() + 0.500);
                break;
            }
        }
    }

    if (loc != null) {
        if (play != null) {
            play.setLocation(loc);
            RedProtect.get().lang.sendMessage(play, RedProtect.get().lang.get("cmdmanager.region.teleport") + " " + rname);
            RedProtect.get().lang.sendMessage(source, RedProtect.get().lang.get("cmdmanager.region.tpother") + " " + rname);
        } else if (source instanceof Player) {
            tpWait((Player) source, loc, rname);
        }
    }
}
 
Example 11
Source File: RTPExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
private void teleportPlayer(Player player, Optional<Location<World>> optionalLocation) {
	player.setLocation(optionalLocation.get());
	player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleporting you to nearest safe location!"));
}
 
Example 12
Source File: BackExecutor.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;

		if (Utils.isLastDeathInConfig(player))
		{
			Location<World> location = Utils.getLastTeleportOrDeathLocation(player);

			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 Last Location. Please wait " + Utils.getTeleportCooldown() + " seconds."));
				
				Sponge.getScheduler().createTaskBuilder().execute(() -> {
					if(EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
					{
						if (player.getLocation().getExtent().getUniqueId().equals(location.getExtent().getUniqueId()))
							player.setLocation(location);
						else
							player.transferToWorld(location.getExtent().getUniqueId(), location.getPosition());
						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
			{
				if (player.getLocation().getExtent().getUniqueId().equals(location.getExtent().getUniqueId()))
					player.setLocation(location);
				else
					player.transferToWorld(location.getExtent().getUniqueId(), location.getPosition());
				src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to Last Location."));
			}
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Last death location not found!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /back!"));
	}

	return CommandResult.success();
}
 
Example 13
Source File: PlayerTickTask.java    From GriefDefender with MIT License 4 votes vote down vote up
@Override
public void run() {
    for (World world : Sponge.getServer().getWorlds()) {
        for (Player player : world.getPlayers()) {
            if (player.isRemoved()) {
                continue;
            }
            final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
            final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
            // send queued visuals
            int count = 0;
            final Iterator<BlockSnapshot> iterator = playerData.queuedVisuals.iterator();
            while (iterator.hasNext()) {
                final BlockSnapshot snapshot = iterator.next();
                if (count > GriefDefenderPlugin.getGlobalConfig().getConfig().visual.clientVisualsPerTick) {
                    break;
                }
                player.sendBlockChange(snapshot.getPosition(), snapshot.getState());
                iterator.remove();
                count++;
            }

            // chat capture
            playerData.updateRecordChat();
            // health regen
            if (world.getProperties().getTotalTime() % 100 == 0L) {
                final GameMode gameMode = player.get(Keys.GAME_MODE).get();
                // Handle player health regen
                if (gameMode != GameModes.CREATIVE && gameMode != GameModes.SPECTATOR && GDOptions.isOptionEnabled(Options.PLAYER_HEALTH_REGEN)) {
                    final double maxHealth = player.get(Keys.MAX_HEALTH).get();
                    final double currentHealth = player.get(Keys.HEALTH).get();
                    if (currentHealth < maxHealth) {
                        final double regenAmount = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_HEALTH_REGEN, claim);
                        if (regenAmount > 0) {
                            final double newHealth = currentHealth + regenAmount;
                            if (newHealth > maxHealth) {
                                player.offer(Keys.MAX_HEALTH, maxHealth);
                            } else {
                                player.offer(Keys.HEALTH, newHealth);
                            }
                        }
                    }
                }
            }
            // teleport delay
            if (world.getProperties().getTotalTime() % 20 == 0L) {
                if (playerData.teleportDelay > 0) {
                    final int delay = playerData.teleportDelay - 1;
                    if (delay == 0) {
                        player.setLocation(playerData.teleportLocation);
                        playerData.teleportDelay = 0;
                        playerData.teleportLocation = null;
                        playerData.teleportSourceLocation = null;
                        continue;
                    }
                    TextAdapter.sendComponent(player, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.TELEPORT_DELAY_NOTICE, 
                            ImmutableMap.of("delay", TextComponent.of(delay, TextColor.GOLD))));
                    playerData.teleportDelay = delay;
                }
            }
        }
    }
}
 
Example 14
Source File: CommandHelper.java    From GriefPrevention with MIT License 4 votes vote down vote up
public static Consumer<CommandSource> createForceTeleportConsumer(Player player, Location<World> location) {
    return teleport -> {
        player.setLocation(location);
    };
}
 
Example 15
Source File: CommandHelper.java    From GriefPrevention with MIT License 4 votes vote down vote up
public static Consumer<CommandSource> createTeleportConsumer(CommandSource src, Location<World> location, Claim claim) {
    return teleport -> {
        if (!(src instanceof Player)) {
            // ignore
            return;
        }
        Player player = (Player) src;
        GPClaim gpClaim = (GPClaim) claim;
        GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getPlayerData(player.getWorld(), player.getUniqueId());
        if (!playerData.canIgnoreClaim(gpClaim) && !playerData.canManageAdminClaims) {
            // if not owner of claim, validate perms
            if (!player.getUniqueId().equals(claim.getOwnerUniqueId())) {
                if (!player.hasPermission(GPPermissions.COMMAND_CLAIM_INFO_TELEPORT_OTHERS)) {
                    player.sendMessage(Text.of(TextColors.RED, "You do not have permission to use the teleport feature in this claim.")); 
                    return;
                }
                if (!gpClaim.isUserTrusted(player, TrustType.ACCESSOR)) {
                    if (GriefPreventionPlugin.instance.economyService.isPresent()) {
                        // Allow non-trusted to TP to claims for sale
                        if (!gpClaim.getEconomyData().isForSale()) {
                            player.sendMessage(Text.of(TextColors.RED, "You are not trusted to use the teleport feature in this claim.")); 
                            return;
                        }
                    } else {
                        player.sendMessage(Text.of(TextColors.RED, "You are not trusted to use the teleport feature in this claim.")); 
                        return;
                    }
                }
            } else if (!player.hasPermission(GPPermissions.COMMAND_CLAIM_INFO_TELEPORT_BASE)) {
                player.sendMessage(Text.of(TextColors.RED, "You do not have permission to use the teleport feature in your claim.")); 
                return;
            }
        }

        Location<World> safeLocation = Sponge.getGame().getTeleportHelper().getSafeLocation(location, 64, 16).orElse(null);
        if (safeLocation == null) {
            player.sendMessage(
                    Text.builder().append(Text.of(TextColors.RED, "Location is not safe. "), 
                    Text.builder().append(Text.of(TextColors.GREEN, "Are you sure you want to teleport here?")).onClick(TextActions.executeCallback(createForceTeleportConsumer(player, location))).style(TextStyles.UNDERLINE).build()).build());
        } else {
            player.setLocation(safeLocation);
        }
    };
}
 
Example 16
Source File: CommandClaimSpawn.java    From GriefDefender with MIT License 4 votes vote down vote up
@CommandAlias("claimspawn")
@Description("Teleports you to claim spawn if available.")
@Syntax("[name] [user]")
@Subcommand("claim spawn")
public void execute(Player player, @Optional String claimName, @Optional User targetPlayer) {
    final GDPlayerData srcPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GDPlayerData targetPlayerData = null;
    if (targetPlayer != null) {
        targetPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), targetPlayer.getUniqueId());
    } else {
        targetPlayerData = srcPlayerData;
    }

    GDClaim claim = null;
    if (claimName != null) {
        for (Claim playerClaim : targetPlayerData.getInternalClaims()) {
            String name = null;
            Component component = playerClaim.getName().orElse(null);
            if (component != null) {
                name = PlainComponentSerializer.INSTANCE.serialize(component);
                if (claimName.equalsIgnoreCase(name)) {
                    claim = (GDClaim) playerClaim;
                    break;
                }
            }
        }
        if (claim == null) {
            GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_CLAIMNAME_NOT_FOUND,
                    ImmutableMap.of("name", claimName)));
            return;
        }
    } else {
        claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(targetPlayerData, player.getLocation());
    }

    if (!srcPlayerData.canIgnoreClaim(claim) && !claim.isUserTrusted(player, TrustTypes.ACCESSOR) && !player.hasPermission(GDPermissions.COMMAND_DELETE_CLAIMS)) {
        GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ACCESS,
                ImmutableMap.of("player", claim.getOwnerDisplayName())));
        return;
    }

    final Vector3i spawnPos = claim.getData().getSpawnPos().orElse(null);
    if (spawnPos == null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().SPAWN_NOT_SET);
        return;
    }

    final Location<World> spawnLocation = new Location<>(claim.getWorld(), spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
    int teleportDelay = 0;
    if (GDOptions.isOptionEnabled(Options.PLAYER_TELEPORT_DELAY)) {
        teleportDelay = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.PLAYER_TELEPORT_DELAY, claim);
    }
    if (teleportDelay > 0) {
        srcPlayerData.teleportDelay = teleportDelay + 1;
        srcPlayerData.teleportLocation = spawnLocation;
        return;
    }
    player.setLocation(spawnLocation);
    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.SPAWN_TELEPORT,
            ImmutableMap.of(
            "location", spawnPos));
    GriefDefenderPlugin.sendMessage(player, message);
}
 
Example 17
Source File: CommandHelper.java    From GriefDefender with MIT License 4 votes vote down vote up
public static Consumer<CommandSource> createForceTeleportConsumer(Player player, Location<World> location) {
    return teleport -> {
        player.setLocation(location);
    };
}
 
Example 18
Source File: CommandHelper.java    From GriefDefender with MIT License 4 votes vote down vote up
public static Consumer<CommandSource> createTeleportConsumer(CommandSource src, Location<World> location, Claim claim, boolean isClaimSpawn) {
    return teleport -> {
        if (!(src instanceof Player)) {
            // ignore
            return;
        }

        final Player player = (Player) src;
        final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getPlayerData(player.getWorld(), player.getUniqueId());
        final int teleportDelay = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.PLAYER_TELEPORT_DELAY, claim);
        if (isClaimSpawn) {
            if (teleportDelay > 0) {
                playerData.teleportDelay = teleportDelay + 1;
                playerData.teleportSourceLocation = player.getLocation();
                playerData.teleportLocation = location;
                return;
            }

            player.setLocation(location);
            return;
        }

        Location<World> safeLocation = Sponge.getGame().getTeleportHelper().getSafeLocation(location, 64, 16).orElse(null);
        if (safeLocation == null) {
            if (teleportDelay > 0) {
                playerData.teleportDelay = teleportDelay + 1;
                playerData.teleportLocation = location;
                return;
            }
            TextAdapter.sendComponent(player, TextComponent.builder("")
                    .append("Location is not safe. ", TextColor.RED)
                    .append(TextComponent.builder("")
                            .append("Are you sure you want to teleport here?", TextColor.GREEN)
                            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createForceTeleportConsumer(player, location)))).decoration(TextDecoration.UNDERLINED, true).build()).build());
        } else {
            if (teleportDelay > 0) {
                playerData.teleportDelay = teleportDelay + 1;
                playerData.teleportLocation = safeLocation;
                return;
            }
            player.setLocation(safeLocation);
        }
    };
}