Skip to content

Commit

Permalink
Switched from Saving Location to Saving Transform
Browse files Browse the repository at this point in the history
- Homes, Warps, and Spawn will now save their rotation data when set.
Previously set homes, warps, and spawns will continue to work, but
unless they are set once more, they will not retain rotation. This means
if you set a home, spawn, or warp, while looking down, anybody who
teleports there will also be looking down.
  • Loading branch information
hsyyid committed Feb 26, 2016
1 parent e594d7b commit b78fa41
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CommandResult execute(CommandSource src, CommandContext ctx) throws Comma
{
Player player = (Player) src;

if (Utils.isHomeInConfig(player.getUniqueId(), homeName) && Utils.getHome(player.getUniqueId(), homeName) != null)
if (Utils.isHomeInConfig(player.getUniqueId(), homeName))
{
try
{
Expand All @@ -69,9 +69,14 @@ public CommandResult execute(CommandSource src, CommandContext ctx) throws Comma
Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

if (Objects.equals(player.getWorld().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId()))
player.setLocation(Utils.getHome(player.getUniqueId(), homeName));
{
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 " + homeName));
EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
Expand All @@ -83,9 +88,14 @@ public CommandResult execute(CommandSource src, CommandContext ctx) throws Comma
Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

if (Objects.equals(player.getWorld().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId()))
player.setLocation(Utils.getHome(player.getUniqueId(), homeName));
{
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 " + homeName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand All @@ -53,7 +53,7 @@ public void executeAsync(CommandSource src, CommandContext ctx)
{
Player player = (Player) src;

ArrayList<String> homes = Utils.getHomes(player.getUniqueId());
Set<Object> homes = Utils.getHomes(player.getUniqueId());

if (homes.size() == 0)
{
Expand All @@ -64,8 +64,10 @@ public void executeAsync(CommandSource src, CommandContext ctx)
PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
List<Text> homeText = Lists.newArrayList();

for (String name : homes)
for (Object home : homes)
{
String name = String.valueOf(home);

Text item = Text.builder(name)
.onClick(TextActions.runCommand("/home " + name))
.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Teleport to home ", TextColors.GOLD, name)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand All @@ -54,7 +54,7 @@ public void executeAsync(CommandSource src, CommandContext ctx)
if (src instanceof Player)
{
Player player = (Player) src;
ArrayList<String> warps = Utils.getWarps();
Set<Object> warps = Utils.getWarps();

if (warps.size() == 0)
{
Expand All @@ -67,13 +67,13 @@ public void executeAsync(CommandSource src, CommandContext ctx)
PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
List<Text> warpText = Lists.newArrayList();

for (String name : warps)
for (Object name : warps)
{
if (player.hasPermission("essentialcmds.warp.use." + name))
if (player.hasPermission("essentialcmds.warp.use." + String.valueOf(name)))
{
Text item = Text.builder(name)
.onClick(TextActions.runCommand("/warp " + name))
.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Warp to ", TextColors.GOLD, name)))
Text item = Text.builder(String.valueOf(name))
.onClick(TextActions.runCommand("/warp " + String.valueOf(name)))
.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Warp to ", TextColors.GOLD, String.valueOf(name))))
.color(TextColors.DARK_AQUA)
.style(TextStyles.UNDERLINE)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,31 @@ public void executeAsync(CommandSource src, CommandContext ctx)
homesAllowed = ((OptionSubject) subject).getOption("homes").orElse("");
}

if (homesAllowed != null && !(homesAllowed.equals("")))
if (homesAllowed != null && !homesAllowed.isEmpty())
{
if (homesAllowed.equals("unlimited"))
{
Utils.setHome(player.getUniqueId(), player.getLocation(), player.getWorld().getName(), homeName);
Utils.setHome(player.getUniqueId(), player.getTransform(), player.getWorld().getName(), homeName);
src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Home set."));
}
else
{
Integer allowedHomes = Integer.parseInt(homesAllowed);
try

if (allowedHomes > Utils.getHomes(player.getUniqueId()).size())
{
if (allowedHomes > Utils.getHomes(player.getUniqueId()).size())
{
Utils.setHome(player.getUniqueId(), player.getLocation(), player.getWorld().getName(), homeName);
src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Home set."));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You have reached the maximum number of homes you are allowed!"));
}
Utils.setHome(player.getUniqueId(), player.getTransform(), player.getWorld().getName(), homeName);
src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Home set."));
}
catch (NullPointerException e)
else
{
if (allowedHomes > 0)
{
Utils.setHome(player.getUniqueId(), player.getLocation(), player.getWorld().getName(), homeName);
src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Home set."));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You have reached the maximum number of homes you are allowed!"));
}
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You have reached the maximum number of homes you are allowed!"));
}
}
}
else
{
Utils.setHome(player.getUniqueId(), player.getLocation(), player.getWorld().getName(), homeName);
Utils.setHome(player.getUniqueId(), player.getTransform(), player.getWorld().getName(), homeName);
src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Home set."));
}
}
Expand All @@ -116,7 +102,8 @@ public String[] getAliases()
public CommandSpec getSpec()
{
return CommandSpec.builder()
.description(Text.of("Set Home Command")).permission("essentialcmds.home.set")
.description(Text.of("Set Home Command"))
.permission("essentialcmds.home.set")
.arguments(GenericArguments.onlyOne(GenericArguments.string(Text.of("home name"))))
.executor(this)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public CommandResult execute(CommandSource src, CommandContext ctx) throws Comma
if (src instanceof Player)
{
Player player = (Player) src;
Utils.setSpawn(player.getLocation(), player.getWorld().getName());
Utils.setSpawn(player.getTransform(), player.getWorld().getName());
player.getWorld().getProperties().setSpawnPosition(player.getLocation().getBlockPosition());
src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Spawn set."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.source.CommandBlockSource;
import org.spongepowered.api.command.source.ConsoleSource;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
Expand All @@ -44,32 +42,35 @@ public class SetWarpExecutor extends AsyncCommandExecutorBase
public void executeAsync(CommandSource src, CommandContext ctx)
{
String warpName = ctx.<String> getOne("warp name").get();

if (src instanceof Player)
{
Player player = (Player) src;
Utils.setWarp(player.getLocation(), warpName);
Utils.setWarp(player.getTransform(), warpName);
src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Warp set."));
}
else if (src instanceof ConsoleSource)
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /setwarp!"));
}
else if (src instanceof CommandBlockSource)
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /setwarp!"));
}
}

@Nonnull
@Override
public String[] getAliases() {
public String[] getAliases()
{
return new String[] { "setwarp" };
}

@Nonnull
@Override
public CommandSpec getSpec() {
return CommandSpec.builder().description(Text.of("Set Warp Command")).permission("essentialcmds.warp.set")
.arguments(GenericArguments.onlyOne(GenericArguments.string(Text.of("warp name")))).executor(this).build();
public CommandSpec getSpec()
{
return CommandSpec.builder()
.description(Text.of("Set Warp Command"))
.permission("essentialcmds.warp.set")
.arguments(GenericArguments.onlyOne(GenericArguments.string(Text.of("warp name"))))
.executor(this)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@
*/
package io.github.hsyyid.essentialcmds.cmdexecutors;

import io.github.hsyyid.essentialcmds.EssentialCmds;
import io.github.hsyyid.essentialcmds.internal.CommandExecutorBase;
import io.github.hsyyid.essentialcmds.utils.Utils;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.entity.Transform;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

Expand All @@ -48,20 +51,51 @@ public CommandResult execute(CommandSource src, CommandContext ctx) throws Comma
if (src instanceof Player)
{
Player player = (Player) src;
Location<World> spawn = Utils.getSpawn();
Transform<World> spawn = Utils.getSpawn();

if (Utils.isSpawnInConfig() && spawn != null)
if (Utils.isSpawnInConfig())
{
if (!Objects.equals(player.getWorld().getUniqueId(), spawn.getExtent().getUniqueId()))
if (Utils.isTeleportCooldownEnabled() && !player.hasPermission("essentialcmds.teleport.cooldown.override"))
{
player.transferToWorld(spawn.getExtent().getUniqueId(), spawn.getPosition());
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("EssentialCmds").get().getInstance().get());
}
else
{
player.setLocation(spawn);
}
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"));
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to Spawn"));
}
}
else
{
Expand All @@ -87,6 +121,10 @@ public String[] getAliases()
@Override
public CommandSpec getSpec()
{
return CommandSpec.builder().description(Text.of("Spawn Command")).permission("essentialcmds.spawn.use").executor(this).build();
return CommandSpec.builder()
.description(Text.of("Spawn Command"))
.permission("essentialcmds.spawn.use")
.executor(this)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.entity.Transform;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.Objects;
Expand All @@ -48,20 +48,21 @@ public class UnJailExecutor extends CommandExecutorBase
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
Player target = ctx.<Player> getOne("target").get();
Location<World> spawn = Utils.getSpawn();
Transform<World> spawn = Utils.getSpawn();

if(EssentialCmds.jailedPlayers.contains(target.getUniqueId()))
if (EssentialCmds.jailedPlayers.contains(target.getUniqueId()))
{
if (!Objects.equals(target.getWorld().getUniqueId(), spawn.getExtent().getUniqueId()))
{
target.transferToWorld(spawn.getExtent().getUniqueId(), spawn.getPosition());
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to Spawn"));
target.setTransform(spawn);
}
else
{
target.setLocation(spawn);
target.setTransform(spawn);
}


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."));
}
Expand All @@ -75,13 +76,15 @@ public CommandResult execute(CommandSource src, CommandContext ctx) throws Comma

@Nonnull
@Override
public String[] getAliases() {
public String[] getAliases()
{
return new String[] { "unjail" };
}

@Nonnull
@Override
public CommandSpec getSpec() {
public CommandSpec getSpec()
{
return CommandSpec.builder()
.description(Text.of("Un-Jail Command"))
.permission("essentialcmds.unjail.use")
Expand Down
Loading

0 comments on commit b78fa41

Please sign in to comment.