mirror of
https://github.com/plexusorg/Module-Guilds.git
synced 2024-11-23 12:35:00 +00:00
Start owner command, untested because invite doesn't exist loll
This commit is contained in:
parent
7a7471da05
commit
e51922b1da
@ -62,6 +62,8 @@ public class Guilds extends PlexModule
|
||||
this.addDefaultMessage("guildNotFound", "<red>You're currently not a part of a guild!");
|
||||
this.addDefaultMessage("alreadyInGuild", "<red>You're currently in a guild. Please do <gold>/guild leave<red> if you're a member, or if you're an owner with members, <gold>/guild promote <player><red> then <gold>/guild leave<red>, or just an owner, <gold>/guild disband<red>.");
|
||||
this.addDefaultMessage("guildNotOwner", "<red>You're not the owner of this guild!");
|
||||
this.addDefaultMessage("guildMemberNotFound", "<red>This guild member could not be found!");
|
||||
this.addDefaultMessage("guildOwnerSet", "<green>You have successfully promoted <dark_green>{0}<green> to be the new guild owner. You have been set to a default guild member.");
|
||||
|
||||
this.addDefaultMessage("guildPrefixSet", "<green>You have changed the guild prefix to '<gold>{0}</gold><green>'", "0 - The new prefix");
|
||||
this.addDefaultMessage("guildPrefixCleared", "<green>Your guild's prefix has been cleared.");
|
||||
|
@ -40,6 +40,7 @@ public class GuildCommand extends PlexCommand
|
||||
this.registerSubCommand(new ChatSubCommand());
|
||||
this.registerSubCommand(new SetHomeSubCommand());
|
||||
this.registerSubCommand(new HomeSubCommand());
|
||||
this.registerSubCommand(new OwnerSubCommand());
|
||||
} catch (Exception e)
|
||||
{
|
||||
GuildUtil.throwExceptionSync(e);
|
||||
|
62
src/main/java/dev/plex/command/sub/OwnerSubCommand.java
Normal file
62
src/main/java/dev/plex/command/sub/OwnerSubCommand.java
Normal file
@ -0,0 +1,62 @@
|
||||
package dev.plex.command.sub;
|
||||
|
||||
import dev.plex.Guilds;
|
||||
import dev.plex.cache.DataUtils;
|
||||
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.guild.data.Member;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
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 = "owner", aliases = "setowner", usage = "/guild <command> <player name>", description = "Sets the guild owner")
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.owner")
|
||||
public class OwnerSubCommand extends PlexCommand
|
||||
{
|
||||
public OwnerSubCommand()
|
||||
{
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
assert player != null;
|
||||
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
|
||||
{
|
||||
if (!guild.getOwner().getUuid().equals(player.getUniqueId()))
|
||||
{
|
||||
send(player, messageComponent("guildNotOwner"));
|
||||
return;
|
||||
}
|
||||
Member memberSender = guild.getMember(player.getUniqueId());
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[0], false);
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
send(player, messageComponent("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
Member member = guild.getMember(plexPlayer.getUuid());
|
||||
if (member == null)
|
||||
{
|
||||
send(player, messageComponent("guildMemberNotFound"));
|
||||
return;
|
||||
}
|
||||
guild.setOwner(member);
|
||||
guild.getMembers().remove(member);
|
||||
guild.getMembers().add(memberSender);
|
||||
send(player, messageComponent("guildOwnerSet", plexPlayer.getName()));
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -103,9 +103,9 @@ public class SQLGuildManager
|
||||
while (set.next())
|
||||
{
|
||||
Guild guild = new Guild(UUID.fromString(set.getString("guildUuid")),
|
||||
set.getString("name"),
|
||||
GSON.fromJson(set.getString("owner"), Member.class),
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("createdAt")), ZoneId.of(Plex.get().config.getString("server.timezone")).getRules().getOffset(Instant.now())));
|
||||
guild.setName(set.getString("name"));
|
||||
guild.setOwner(GSON.fromJson(set.getString("owner"), Member.class));
|
||||
guild.getMembers().addAll(new Gson().fromJson(set.getString("members"), new TypeToken<List<Member>>()
|
||||
{
|
||||
}.getType()));
|
||||
|
@ -8,7 +8,9 @@ import dev.plex.Plex;
|
||||
import dev.plex.guild.data.Member;
|
||||
import dev.plex.guild.data.Rank;
|
||||
import dev.plex.util.CustomLocation;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import lombok.Data;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.ZoneId;
|
||||
@ -20,14 +22,14 @@ import java.util.*;
|
||||
public class Guild
|
||||
{
|
||||
private final UUID guildUuid;
|
||||
private final String name;
|
||||
private final Member owner;
|
||||
private final ZonedDateTime createdAt;
|
||||
private transient final List<UUID> outgoingInvitations = Lists.newArrayList();
|
||||
private final List<Member> members = Lists.newArrayList();
|
||||
private final List<UUID> moderators = Lists.newArrayList();
|
||||
private final List<Rank> ranks = Lists.newArrayList();
|
||||
private final Map<String, CustomLocation> warps = Maps.newHashMap();
|
||||
private String name;
|
||||
private Member owner;
|
||||
private String prefix;
|
||||
private String motd;
|
||||
private CustomLocation home;
|
||||
@ -38,12 +40,19 @@ public class Guild
|
||||
|
||||
public static Guild create(Player player, String guildName)
|
||||
{
|
||||
return new Guild(UUID.randomUUID(), guildName, new Member(player.getUniqueId()), ZonedDateTime.now(ZoneId.of(Plex.get().config.getString("server.timezone"))));
|
||||
Guild guild = new Guild(UUID.randomUUID(), ZonedDateTime.now(ZoneId.of(Plex.get().config.getString("server.timezone"))));
|
||||
guild.setName(PlainTextComponentSerializer.plainText().serialize(SafeMiniMessage.mmDeserialize(guildName)));
|
||||
guild.setOwner(new Member(player.getUniqueId()));
|
||||
return guild;
|
||||
}
|
||||
|
||||
public Member getMember(UUID uuid)
|
||||
{
|
||||
return owner.getUuid().equals(uuid) ? owner : members.stream().filter(member -> member.getUuid().equals(uuid)).findFirst().get();
|
||||
if (owner.getUuid().equals(uuid))
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
return members.stream().filter(m -> m.getUuid().equals(uuid)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public List<Member> getMembers()
|
||||
|
Loading…
Reference in New Issue
Block a user