Add setting home, removing it, and teleporting to it

This commit is contained in:
Taah
2022-05-08 17:15:22 -07:00
parent 1e43e49604
commit a919627aba
7 changed files with 143 additions and 34 deletions

View File

@ -37,6 +37,8 @@ public class GuildCommand extends PlexCommand
this.registerSubCommand(new WarpSubCommand());
this.registerSubCommand(new WarpListSubCommand());
this.registerSubCommand(new ChatSubCommand());
this.registerSubCommand(new SetHomeSubCommand());
this.registerSubCommand(new HomeSubCommand());
} catch (Exception e)
{
GuildUtil.throwExceptionSync(e);

View File

@ -0,0 +1,38 @@
package dev.plex.command.sub;
import dev.plex.Guilds;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "home", aliases = "spawn", usage = "/guild <command>")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.home")
public class HomeSubCommand extends PlexCommand
{
public HomeSubCommand()
{
super(false);
}
@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> {
if (guild.getHome() == null)
{
send(player, messageComponent("guildHomeNotFound"));
return;
}
player.teleportAsync(guild.getHome().toLocation());
}, () -> send(player, messageComponent("guildNotFound")));
return null;
}
}

View File

@ -36,7 +36,7 @@ public class PrefixSubCommand extends PlexCommand
}
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> {
if (!guild.getOwner().equals(player.getUniqueId()))
if (!guild.getOwner().getUuid().equals(player.getUniqueId()))
{
send(player, messageComponent("guildNotOwner"));
return;

View File

@ -0,0 +1,53 @@
package dev.plex.command.sub;
import dev.plex.Guilds;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.CustomLocation;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "sethome", aliases = "setspawn", usage = "/guild <command>")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.sethome")
public class SetHomeSubCommand extends PlexCommand
{
public SetHomeSubCommand()
{
super(false);
}
@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
{
if (!guild.getOwner().getUuid().equals(player.getUniqueId()))
{
send(player, messageComponent("guildNotOwner"));
return;
}
if (args.length > 0 && (args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("unset") || args[0].equalsIgnoreCase("clear")))
{
if (guild.getHome() == null)
{
send(player, messageComponent("guildHomeNotFound"));
return;
}
guild.setHome(null);
send(player, messageComponent("guildHomeRemoved"));
return;
}
guild.setHome(CustomLocation.fromLocation(player.getLocation()));
send(player, messageComponent("guildHomeSet"));
}, () -> send(player, messageComponent("guildNotFound")));
return null;
}
}

View File

@ -36,7 +36,7 @@ public class SetWarpSubCommand extends PlexCommand
}
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> {
if (!guild.getOwner().equals(player.getUniqueId()))
if (!guild.getOwner().getUuid().equals(player.getUniqueId()))
{
send(player, messageComponent("guildNotOwner"));
return;