mirror of
https://github.com/plexusorg/Module-Guilds.git
synced 2024-10-31 18:17:11 +00:00
- Finish Chat Command
- Finish Warps System - Migrate Owner variable to Member object - Modify Chat Handler to add support for guild chat toggles
This commit is contained in:
parent
8bcf28f120
commit
3d4d73a03e
@ -1,6 +1,7 @@
|
||||
package dev.plex;
|
||||
|
||||
import dev.plex.command.GuildCommand;
|
||||
import dev.plex.config.ModuleConfig;
|
||||
import dev.plex.data.SQLGuildManager;
|
||||
import dev.plex.data.SQLManager;
|
||||
import dev.plex.guild.Guild;
|
||||
@ -25,10 +26,14 @@ public class Guilds extends PlexModule
|
||||
|
||||
private SQLGuildManager sqlGuildManager;
|
||||
|
||||
private ModuleConfig config;
|
||||
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
module = this;
|
||||
config = new ModuleConfig(this, "data/config.yml", "config.yml");
|
||||
config.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,12 +59,18 @@ public class Guilds extends PlexModule
|
||||
this.addDefaultMessage("guildsHelpCommand", "<gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline>\n" +
|
||||
"<newline><gold>/guild <gray>Returns this menu\n" +
|
||||
"<newline><gold>/guild help");
|
||||
this.addDefaultMessage("guildCommandNotFound", "<red>'{0}'<gold> is not a valid sub command!", "0 - The sub command");
|
||||
this.addDefaultMessage("guildCommandNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid sub command!", "0 - The sub command");
|
||||
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("guildPrefixSet", "<green>You have changed the guild prefix to '<gold>{0}</gold>'", "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("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("guildWarpCreated", "<green>You have created a warp called '<dark_green>{0}</dark_green><green>'", "0 - The warp name");
|
||||
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("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");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,9 +5,7 @@ import com.google.common.collect.Lists;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.sub.CreateSubCommand;
|
||||
import dev.plex.command.sub.InfoSubCommand;
|
||||
import dev.plex.command.sub.PrefixSubCommand;
|
||||
import dev.plex.command.sub.*;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.GuildUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
@ -35,6 +33,10 @@ public class GuildCommand extends PlexCommand
|
||||
this.registerSubCommand(new CreateSubCommand());
|
||||
this.registerSubCommand(new InfoSubCommand());
|
||||
this.registerSubCommand(new PrefixSubCommand());
|
||||
this.registerSubCommand(new SetWarpSubCommand());
|
||||
this.registerSubCommand(new WarpSubCommand());
|
||||
this.registerSubCommand(new WarpListSubCommand());
|
||||
this.registerSubCommand(new ChatSubCommand());
|
||||
} catch (Exception e)
|
||||
{
|
||||
GuildUtil.throwExceptionSync(e);
|
||||
|
55
src/main/java/dev/plex/command/sub/ChatSubCommand.java
Normal file
55
src/main/java/dev/plex/command/sub/ChatSubCommand.java
Normal file
@ -0,0 +1,55 @@
|
||||
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.guild.data.Member;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@CommandParameters(name = "chat", usage = "/guild <command> [message]")
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.chat")
|
||||
public class ChatSubCommand extends PlexCommand
|
||||
{
|
||||
public ChatSubCommand()
|
||||
{
|
||||
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 (args.length == 0)
|
||||
{
|
||||
Member member = guild.getMember(player.getUniqueId());
|
||||
member.setChat(!member.isChat());
|
||||
send(player, messageComponent("guildChatToggled", BooleanUtils.toStringOnOff(member.isChat())));
|
||||
return;
|
||||
}
|
||||
guild.getMembers().stream().map(Member::getPlayer).filter(Objects::nonNull).forEach(player1 ->
|
||||
{
|
||||
send(player1, messageComponent("guildChatMessage", player.getName(), StringUtils.join(args, ", ")));
|
||||
});
|
||||
if (Guilds.get().getConfig().isBoolean("guilds.log-chat-message"))
|
||||
{
|
||||
send(Bukkit.getConsoleSender(), messageComponent("guildChatConsoleLog", guild.getName(), guild.getGuildUuid(), player.getName(), StringUtils.join(args, ", ")));
|
||||
}
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ public class InfoSubCommand extends PlexCommand
|
||||
}
|
||||
|
||||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a");
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] strings)
|
||||
{
|
||||
@ -39,19 +40,16 @@ public class InfoSubCommand extends PlexCommand
|
||||
send(player, mmString(""));
|
||||
try
|
||||
{
|
||||
send(player, mmString("<gold>Owner: <yellow>" + DataUtils.getPlayer(guild.getOwner(), false).getName()));
|
||||
send(player, mmString("<gold>Owner: <yellow>" + DataUtils.getPlayer(guild.getOwner().getUuid(), false).getName()));
|
||||
} catch (NullPointerException e)
|
||||
{
|
||||
send(player, mmString("<gold>Owner: <yellow>Unable to load cache..."));
|
||||
}
|
||||
send(player, mmString("<gold>Members (" + guild.getMembers().size() + "): " + StringUtils.join(guild.getMembers().stream().map(member -> DataUtils.getPlayer(member.uuid(), false).getName()).toList(), ", ")));
|
||||
send(player, mmString("<gold>Members (" + guild.getMembers().size() + "): " + StringUtils.join(guild.getMembers().stream().map(member -> DataUtils.getPlayer(member.getUuid(), false).getName()).toList(), ", ")));
|
||||
send(player, mmString("<gold>Moderators (" + guild.getModerators().size() + "): " + StringUtils.join(guild.getModerators().stream().map(uuid -> DataUtils.getPlayer(uuid, false).getName()).toList(), ", ")));
|
||||
send(player, mmString("<gold>Prefix: " + (guild.getPrefix() == null ? "N/A" : guild.getPrefix())));
|
||||
send(player, mmString("<gold>Created At: " + formatter.format(guild.getCreatedAt())));
|
||||
}, () ->
|
||||
{
|
||||
send(player, messageComponent("guildNotFound"));
|
||||
});
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class PrefixSubCommand extends PlexCommand
|
||||
}
|
||||
guild.setPrefix(StringUtils.join(args, " "));
|
||||
send(player, messageComponent("guildPrefixSet", SafeMiniMessage.mmDeserializeWithoutEvents(guild.getPrefix())));
|
||||
}, () -> send(player, messageComponent("alreadyInGuild")));
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
55
src/main/java/dev/plex/command/sub/SetWarpSubCommand.java
Normal file
55
src/main/java/dev/plex/command/sub/SetWarpSubCommand.java
Normal file
@ -0,0 +1,55 @@
|
||||
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 dev.plex.util.minimessage.SafeMiniMessage;
|
||||
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 = "setwarp", aliases = "makewarp,createwarp", usage = "/guild <command> <name>")
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.setwarp")
|
||||
public class SetWarpSubCommand extends PlexCommand
|
||||
{
|
||||
public SetWarpSubCommand()
|
||||
{
|
||||
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().equals(player.getUniqueId()))
|
||||
{
|
||||
send(player, messageComponent("guildNotOwner"));
|
||||
return;
|
||||
}
|
||||
if (args[0].length() > 16)
|
||||
{
|
||||
send(player, mmString("<red>The max length of a warp name is 16 characters!"));
|
||||
return;
|
||||
}
|
||||
if (guild.getWarps().containsKey(args[0].toLowerCase()))
|
||||
{
|
||||
send(player, messageComponent("guildWarpExists", args[0]));
|
||||
return;
|
||||
}
|
||||
guild.getWarps().put(args[0].toLowerCase(), CustomLocation.fromLocation(player.getLocation()));
|
||||
send(player, messageComponent("guildWarpCreated", args[0]));
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
return null;
|
||||
}
|
||||
}
|
37
src/main/java/dev/plex/command/sub/WarpListSubCommand.java
Normal file
37
src/main/java/dev/plex/command/sub/WarpListSubCommand.java
Normal file
@ -0,0 +1,37 @@
|
||||
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.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@CommandParameters(name = "warps", aliases = "listwarps", usage = "/guild <command>")
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warps")
|
||||
public class WarpListSubCommand extends PlexCommand
|
||||
{
|
||||
public WarpListSubCommand()
|
||||
{
|
||||
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 -> {
|
||||
Set<String> warps = guild.getWarps().keySet();
|
||||
send(player, mmString("<gold>Warps (" + warps.size() + "): " + StringUtils.join(warps, ", ")));
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
return null;
|
||||
}
|
||||
}
|
42
src/main/java/dev/plex/command/sub/WarpSubCommand.java
Normal file
42
src/main/java/dev/plex/command/sub/WarpSubCommand.java
Normal file
@ -0,0 +1,42 @@
|
||||
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 = "warp", aliases = "goto", usage = "/guild <command> <name>")
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warp")
|
||||
public class WarpSubCommand extends PlexCommand
|
||||
{
|
||||
public WarpSubCommand()
|
||||
{
|
||||
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.getWarps().containsKey(args[0].toLowerCase()))
|
||||
{
|
||||
send(player, messageComponent("guildWarpNotFound", args[0]));
|
||||
return;
|
||||
}
|
||||
player.teleportAsync(guild.getWarps().get(args[0].toLowerCase()).toLocation());
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -5,8 +5,10 @@ import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.guild.Guild;
|
||||
import dev.plex.guild.data.Member;
|
||||
import dev.plex.util.CustomLocation;
|
||||
import dev.plex.util.GuildUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -17,6 +19,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
@ -26,11 +29,9 @@ public class SQLGuildManager
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
private static final String SELECT_GUILD = "SELECT * FROM `guilds`";
|
||||
private static final String SELECT_GUILD_OWNER = "SELECT * FROM `guilds` WHERE owner=?";
|
||||
private static final String SELECT_GUILD_MEMBER_MYSQL = "SELECT * FROM `guilds` WHERE json_search(members, ?, ?) IS NOT NULL LIMIT 1";
|
||||
private static final String INSERT_GUILD = "INSERT INTO `guilds` (`guildUuid`, `name`, `owner`, `createdAt`, `members`, `moderators`, `prefix`, `motd`, `ranks`, `defaultRank`, `home`, `tagEnabled`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String DELETE_GUILD = "DELETE FROM `guilds` WHERE owner=?";
|
||||
private static final String UPDATE_GUILD = "UPDATE `guilds` SET name=?, owner=?, members=?, moderators=?, prefix=?, motd=?, ranks=?, defaultRank=?, home=?, tagEnabled=? WHERE guildUuid=?";
|
||||
private static final String INSERT_GUILD = "INSERT INTO `guilds` (`guildUuid`, `name`, `owner`, `createdAt`, `members`, `moderators`, `prefix`, `motd`, `ranks`, `defaultRank`, `warps`, `home`, `tagEnabled`, `isPublic`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String DELETE_GUILD = "DELETE FROM `guilds` WHERE guildUuid=?";
|
||||
private static final String UPDATE_GUILD = "UPDATE `guilds` SET name=?, owner=?, members=?, moderators=?, prefix=?, motd=?, ranks=?, defaultRank=?, home=?, warps=?, tagEnabled=?, isPublic=? WHERE guildUuid=?";
|
||||
|
||||
public CompletableFuture<Guild> insertGuild(Guild guild)
|
||||
{
|
||||
@ -41,7 +42,7 @@ public class SQLGuildManager
|
||||
PreparedStatement statement = connection.prepareStatement(INSERT_GUILD);
|
||||
statement.setString(1, guild.getGuildUuid().toString());
|
||||
statement.setString(2, guild.getName());
|
||||
statement.setString(3, guild.getOwner().toString());
|
||||
statement.setString(3, GSON.toJson(guild.getOwner()));
|
||||
statement.setLong(4, guild.getCreatedAt().toInstant().toEpochMilli());
|
||||
statement.setString(5, GSON.toJson(guild.getMembers()));
|
||||
statement.setString(6, GSON.toJson(guild.getModerators().stream().map(UUID::toString).collect(Collectors.toList())));
|
||||
@ -49,8 +50,10 @@ public class SQLGuildManager
|
||||
statement.setString(8, guild.getMotd());
|
||||
statement.setString(9, GSON.toJson(guild.getRanks()));
|
||||
statement.setString(10, GSON.toJson(guild.getDefaultRank()));
|
||||
statement.setString(11, GSON.toJson(guild.getHome()));
|
||||
statement.setBoolean(12, guild.isTagEnabled());
|
||||
statement.setString(11, GSON.toJson(guild.getWarps()));
|
||||
statement.setString(12, GSON.toJson(guild.getHome()));
|
||||
statement.setBoolean(13, guild.isTagEnabled());
|
||||
statement.setBoolean(14, guild.isPublic());
|
||||
statement.execute();
|
||||
return guild;
|
||||
} catch (SQLException e)
|
||||
@ -69,7 +72,7 @@ public class SQLGuildManager
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
|
||||
statement.setString(1, guild.getName());
|
||||
statement.setString(2, guild.getOwner().toString());
|
||||
statement.setString(2, GSON.toJson(guild.getOwner()));
|
||||
statement.setString(3, GSON.toJson(guild.getMembers()));
|
||||
statement.setString(4, GSON.toJson(guild.getModerators().stream().map(UUID::toString).collect(Collectors.toList())));
|
||||
statement.setString(5, guild.getPrefix());
|
||||
@ -77,8 +80,10 @@ public class SQLGuildManager
|
||||
statement.setString(7, GSON.toJson(guild.getRanks()));
|
||||
statement.setString(8, GSON.toJson(guild.getDefaultRank()));
|
||||
statement.setString(9, GSON.toJson(guild.getHome()));
|
||||
statement.setBoolean(10, guild.isTagEnabled());
|
||||
statement.setString(11, guild.getGuildUuid().toString());
|
||||
statement.setString(10, GSON.toJson(guild.getWarps()));
|
||||
statement.setBoolean(11, guild.isTagEnabled());
|
||||
statement.setBoolean(12, guild.isPublic());
|
||||
statement.setString(13, guild.getGuildUuid().toString());
|
||||
statement.executeUpdate();
|
||||
return guild;
|
||||
} catch (SQLException e)
|
||||
@ -102,7 +107,7 @@ public class SQLGuildManager
|
||||
{
|
||||
Guild guild = new Guild(UUID.fromString(set.getString("guildUuid")),
|
||||
set.getString("name"),
|
||||
UUID.fromString(set.getString("owner")),
|
||||
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()));
|
||||
@ -110,6 +115,10 @@ public class SQLGuildManager
|
||||
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)
|
||||
|
@ -21,7 +21,7 @@ public class SQLManager
|
||||
"CREATE TABLE IF NOT EXISTS `guilds` (" +
|
||||
"`guildUuid` VARCHAR(46) NOT NULL, " +
|
||||
"`name` VARCHAR(2000) NOT NULL, " +
|
||||
"`owner` VARCHAR(46) NOT NULL, " +
|
||||
"`owner` LONGTEXT NOT NULL, " +
|
||||
"`createdAt` BIGINT NOT NULL, " +
|
||||
"`prefix` VARCHAR(2000), " +
|
||||
"`motd` VARCHAR(3000), " +
|
||||
@ -30,7 +30,9 @@ public class SQLManager
|
||||
"`moderators` LONGTEXT, " +
|
||||
"`ranks` LONGTEXT, " +
|
||||
"`defaultRank` LONGTEXT, " +
|
||||
"`warps` LONGTEXT, " +
|
||||
"`tagEnabled` BOOLEAN, " +
|
||||
"`isPublic` BOOLEAN, " +
|
||||
"PRIMARY KEY (`guildUuid`)" +
|
||||
");"
|
||||
).execute();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.plex.guild;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Transient;
|
||||
import dev.plex.Plex;
|
||||
@ -12,8 +13,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
@Entity("guilds")
|
||||
@ -21,20 +21,35 @@ public class Guild
|
||||
{
|
||||
private final UUID guildUuid;
|
||||
private final String name;
|
||||
private final UUID owner;
|
||||
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 prefix;
|
||||
private String motd;
|
||||
private CustomLocation home;
|
||||
private boolean tagEnabled;
|
||||
private Rank defaultRank = new Rank("default", null);
|
||||
private boolean isPublic = false;
|
||||
|
||||
|
||||
public static Guild create(Player player, String guildName)
|
||||
{
|
||||
return new Guild(UUID.randomUUID(), guildName, player.getUniqueId(), ZonedDateTime.now(ZoneId.of(Plex.get().config.getString("server.timezone"))));
|
||||
return new Guild(UUID.randomUUID(), guildName, new Member(player.getUniqueId()), ZonedDateTime.now(ZoneId.of(Plex.get().config.getString("server.timezone"))));
|
||||
}
|
||||
|
||||
public Member getMember(UUID uuid)
|
||||
{
|
||||
return owner.getUuid().equals(uuid) ? owner : members.stream().filter(member -> member.getUuid().equals(uuid)).findFirst().get();
|
||||
}
|
||||
|
||||
public List<Member> getMembers()
|
||||
{
|
||||
List<Member> allMembers = Lists.newArrayList(members);
|
||||
allMembers.add(owner);
|
||||
return allMembers;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ public class GuildHolder
|
||||
|
||||
public void deleteGuild(UUID owner)
|
||||
{
|
||||
GUILDS.removeIf(guild -> guild.getOwner().equals(owner));
|
||||
GUILDS.removeIf(guild -> guild.getOwner().getUuid().equals(owner));
|
||||
}
|
||||
|
||||
public Optional<Guild> getGuild(UUID uuid)
|
||||
{
|
||||
return GUILDS.stream().filter(guild -> (guild.getOwner() != null && guild.getOwner().equals(uuid)) || guild.getMembers().stream().map(Member::uuid).toList().contains(uuid)).findFirst();
|
||||
return GUILDS.stream().filter(guild -> (guild.getOwner() != null && guild.getOwner().getUuid().equals(uuid)) || guild.getMembers().stream().map(Member::getUuid).toList().contains(uuid)).findFirst();
|
||||
}
|
||||
|
||||
public Collection<Guild> getGuilds()
|
||||
|
@ -1,7 +1,20 @@
|
||||
package dev.plex.guild.data;
|
||||
|
||||
import lombok.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record Member(UUID uuid, Rank rank)
|
||||
@Data
|
||||
public class Member
|
||||
{
|
||||
private final UUID uuid;
|
||||
private Rank rank;
|
||||
private boolean chat, prefix;
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return Bukkit.getPlayer(this.uuid);
|
||||
}
|
||||
}
|
||||
|
6
src/main/java/dev/plex/guild/data/Permission.java
Normal file
6
src/main/java/dev/plex/guild/data/Permission.java
Normal file
@ -0,0 +1,6 @@
|
||||
package dev.plex.guild.data;
|
||||
|
||||
public enum Permission
|
||||
{
|
||||
SET_WARP, WARPS, DELETE_WARP, WARP
|
||||
}
|
@ -4,6 +4,7 @@ import dev.plex.Guilds;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.api.chat.IChatHandler;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.guild.data.Member;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
@ -17,9 +18,13 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@ -32,6 +37,29 @@ public class ChatHandlerImpl implements IChatHandler
|
||||
public void doChat(AsyncChatEvent event)
|
||||
{
|
||||
event.renderer(renderer);
|
||||
Player player = event.getPlayer();
|
||||
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresent(guild ->
|
||||
{
|
||||
Member member = guild.getMember(player.getUniqueId());
|
||||
if (member == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!member.isChat())
|
||||
{
|
||||
return;
|
||||
}
|
||||
guild.getMembers().stream().map(Member::getPlayer).filter(Objects::nonNull).forEach(player1 ->
|
||||
{
|
||||
player1.sendMessage(PlexUtils.messageComponent("guildChatMessage", player.getName(), PlainTextComponentSerializer.plainText().serialize(event.message())));
|
||||
});
|
||||
if (Guilds.get().getConfig().isBoolean("guilds.log-chat-message"))
|
||||
{
|
||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.messageComponent("guildChatConsoleLog", guild.getName(), guild.getGuildUuid(), player.getName(), PlainTextComponentSerializer.plainText().serialize(event.message())));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static class PlexChatRenderer implements ChatRenderer
|
||||
|
@ -1,7 +1,22 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import lombok.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public record CustomLocation(String worldName, double x, double y, double z, float yaw, float pitch)
|
||||
@Data
|
||||
public class CustomLocation
|
||||
{
|
||||
private final String worldName;
|
||||
private final double x, y, z;
|
||||
private final float yaw, pitch;
|
||||
public static CustomLocation fromLocation(Location location)
|
||||
{
|
||||
return new CustomLocation(location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
public Location toLocation()
|
||||
{
|
||||
return new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
2
src/main/resources/data/config.yml
Normal file
2
src/main/resources/data/config.yml
Normal file
@ -0,0 +1,2 @@
|
||||
guilds:
|
||||
log-chat-message: true
|
Loading…
Reference in New Issue
Block a user