mirror of
https://github.com/plexusorg/Module-Guilds.git
synced 2024-11-23 12:35:00 +00:00
Add setting home, removing it, and teleporting to it
This commit is contained in:
parent
1e43e49604
commit
a919627aba
@ -63,12 +63,19 @@ public class Guilds extends PlexModule
|
|||||||
this.addDefaultMessage("guildNotFound", "<red>You're currently not a part of a guild!");
|
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("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("guildNotOwner", "<red>You're not the owner of this guild!");
|
||||||
|
|
||||||
this.addDefaultMessage("guildPrefixSet", "<green>You have changed the guild prefix to '<gold>{0}</gold><green>'", "0 - The new prefix");
|
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.");
|
this.addDefaultMessage("guildPrefixCleared", "<green>Your guild's prefix has been cleared.");
|
||||||
|
|
||||||
this.addDefaultMessage("guildWarpAlphanumeric", "<red>Warp names may only contain alphabetical and/or numerical characters.");
|
this.addDefaultMessage("guildWarpAlphanumeric", "<red>Warp names may only contain alphabetical and/or numerical characters.");
|
||||||
this.addDefaultMessage("guildWarpExists", "<red>'<gold>{0}</gold>'<red> is already an existing warp!", "0 - The warp name");
|
this.addDefaultMessage("guildWarpExists", "<red>'<gold>{0}</gold>'<red> is already an existing warp!", "0 - The warp name");
|
||||||
this.addDefaultMessage("guildWarpNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid warp!", "0 - The warp name");
|
this.addDefaultMessage("guildWarpNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid warp!", "0 - The warp name");
|
||||||
this.addDefaultMessage("guildWarpCreated", "<green>You have created a warp called '<dark_green>{0}</dark_green><green>'", "0 - The warp name");
|
this.addDefaultMessage("guildWarpCreated", "<green>You have created a warp called '<dark_green>{0}</dark_green><green>'", "0 - The warp name");
|
||||||
|
|
||||||
|
this.addDefaultMessage("guildHomeRemoved", "<green>You have removed the guild's home!");
|
||||||
|
this.addDefaultMessage("guildHomeSet", "<green>You have changed the guild's home!");
|
||||||
|
this.addDefaultMessage("guildHomeNotFound", "<red>This guild currently has no home set.");
|
||||||
|
|
||||||
this.addDefaultMessage("guildChatMessage", "<blue>[GUILD] <aqua>{0} <yellow>{1}", "0 - The player name", "1 - The message");
|
this.addDefaultMessage("guildChatMessage", "<blue>[GUILD] <aqua>{0} <yellow>{1}", "0 - The player name", "1 - The message");
|
||||||
this.addDefaultMessage("guildChatToggled", "<green>Your chat has been toggled {0}", "0 - On / Off");
|
this.addDefaultMessage("guildChatToggled", "<green>Your chat has been toggled {0}", "0 - On / Off");
|
||||||
this.addDefaultMessage("guildChatConsoleLog", "<blue>[GUILD - {0}:{1}] <aqua>{2} <yellow>{3}", "0 - The guild name", "1 - The guild unique identifier", "2 - The player name", "3 - The message");
|
this.addDefaultMessage("guildChatConsoleLog", "<blue>[GUILD - {0}:{1}] <aqua>{2} <yellow>{3}", "0 - The guild name", "1 - The guild unique identifier", "2 - The player name", "3 - The message");
|
||||||
|
@ -37,6 +37,8 @@ public class GuildCommand extends PlexCommand
|
|||||||
this.registerSubCommand(new WarpSubCommand());
|
this.registerSubCommand(new WarpSubCommand());
|
||||||
this.registerSubCommand(new WarpListSubCommand());
|
this.registerSubCommand(new WarpListSubCommand());
|
||||||
this.registerSubCommand(new ChatSubCommand());
|
this.registerSubCommand(new ChatSubCommand());
|
||||||
|
this.registerSubCommand(new SetHomeSubCommand());
|
||||||
|
this.registerSubCommand(new HomeSubCommand());
|
||||||
} catch (Exception e)
|
} catch (Exception e)
|
||||||
{
|
{
|
||||||
GuildUtil.throwExceptionSync(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;
|
assert player != null;
|
||||||
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> {
|
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"));
|
send(player, messageComponent("guildNotOwner"));
|
||||||
return;
|
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;
|
assert player != null;
|
||||||
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> {
|
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"));
|
send(player, messageComponent("guildNotOwner"));
|
||||||
return;
|
return;
|
||||||
|
@ -15,7 +15,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -94,39 +93,49 @@ public class SQLGuildManager
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Guild> getGuildsSync()
|
||||||
|
{
|
||||||
|
List<Guild> guilds = Lists.newArrayList();
|
||||||
|
try (Connection connection = Plex.get().getSqlConnection().getCon())
|
||||||
|
{
|
||||||
|
PreparedStatement statement = connection.prepareStatement(SELECT_GUILD);
|
||||||
|
ResultSet set = statement.executeQuery();
|
||||||
|
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.getMembers().addAll(new Gson().fromJson(set.getString("members"), new TypeToken<List<Member>>()
|
||||||
|
{
|
||||||
|
}.getType()));
|
||||||
|
guild.getModerators().addAll(new Gson().fromJson(set.getString("moderators"), new TypeToken<List<String>>()
|
||||||
|
{
|
||||||
|
}.getType()));
|
||||||
|
guild.setPrefix(set.getString("prefix"));
|
||||||
|
guild.setMotd(set.getString("motd"));
|
||||||
|
guild.setHome(GSON.fromJson(set.getString("home"), CustomLocation.class));
|
||||||
|
guild.setTagEnabled(set.getBoolean("tagEnabled"));
|
||||||
|
Map<String, CustomLocation> warps = GSON.fromJson(set.getString("warps"), new TypeToken<Map<String, CustomLocation>>()
|
||||||
|
{
|
||||||
|
}.getType());
|
||||||
|
PlexLog.debug("Loaded {0} warps for {1} guild", warps.size(), guild.getName());
|
||||||
|
guild.getWarps().putAll(GSON.fromJson(set.getString("warps"), new TypeToken<Map<String, CustomLocation>>()
|
||||||
|
{
|
||||||
|
}.getType()));
|
||||||
|
guild.setPublic(set.getBoolean("isPublic"));
|
||||||
|
guilds.add(guild);
|
||||||
|
}
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
GuildUtil.throwExceptionSync(e);
|
||||||
|
}
|
||||||
|
return guilds;
|
||||||
|
}
|
||||||
|
|
||||||
public CompletableFuture<List<Guild>> getGuilds()
|
public CompletableFuture<List<Guild>> getGuilds()
|
||||||
{
|
{
|
||||||
return CompletableFuture.supplyAsync(() ->
|
return CompletableFuture.supplyAsync(this::getGuildsSync);
|
||||||
{
|
|
||||||
List<Guild> guilds = Lists.newArrayList();
|
|
||||||
try (Connection connection = Plex.get().getSqlConnection().getCon())
|
|
||||||
{
|
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT_GUILD);
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
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.getMembers().addAll(new Gson().fromJson(set.getString("members"), new TypeToken<List<String>>(){}.getType()));
|
|
||||||
guild.getModerators().addAll(new Gson().fromJson(set.getString("moderators"), new TypeToken<List<String>>(){}.getType()));
|
|
||||||
guild.setPrefix(set.getString("prefix"));
|
|
||||||
guild.setMotd(set.getString("motd"));
|
|
||||||
guild.setHome(GSON.fromJson(set.getString("home"), CustomLocation.class));
|
|
||||||
guild.setTagEnabled(set.getBoolean("tagEnabled"));
|
|
||||||
Map<String, CustomLocation> warps = GSON.fromJson(set.getString("warps"), new TypeToken<Map<String, CustomLocation>>(){}.getType());
|
|
||||||
PlexLog.debug("Loaded {0} warps for {1} guild", warps.size(), guild.getName());
|
|
||||||
guild.getWarps().putAll(GSON.fromJson(set.getString("warps"), new TypeToken<Map<String, CustomLocation>>(){}.getType()));
|
|
||||||
guild.setPublic(set.getBoolean("isPublic"));
|
|
||||||
guilds.add(guild);
|
|
||||||
}
|
|
||||||
} catch (SQLException e)
|
|
||||||
{
|
|
||||||
GuildUtil.throwExceptionSync(e);
|
|
||||||
}
|
|
||||||
return guilds;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user