mirror of
https://github.com/plexusorg/Module-Guilds.git
synced 2025-07-01 07:06:41 +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:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user