mirror of
https://github.com/plexusorg/Module-Guilds.git
synced 2025-07-01 07:06:41 +00:00
Add setting home, removing it, and teleporting to it
This commit is contained in:
@ -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);
|
||||
|
38
src/main/java/dev/plex/command/sub/HomeSubCommand.java
Normal file
38
src/main/java/dev/plex/command/sub/HomeSubCommand.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
53
src/main/java/dev/plex/command/sub/SetHomeSubCommand.java
Normal file
53
src/main/java/dev/plex/command/sub/SetHomeSubCommand.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Reference in New Issue
Block a user