Made it where players can't message or reply if they're muted.

This commit is contained in:
nickreesdev 2021-02-20 12:25:02 -06:00
parent 1f933ce804
commit b83c25a5e5
9 changed files with 49 additions and 16 deletions

@ -39,7 +39,7 @@ public class Arcade extends MGZPlugin {
new ScoreboardHandler(this, ArcadeScoreboard.class, 3L);
new ChatManager(this, badSportSystem, new IChatComponent[] {
new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] {
new BasicRankComponent(),
new BasicNameComponent()
});

@ -33,7 +33,7 @@ public class Build extends MGZPlugin {
WorldManager worldManager = new WorldManager(this);
new PlayerListener(this, worldManager);
new ChatManager(this, badSportSystem, new IChatComponent[] {
new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] {
new BasicRankComponent(),
new BasicNameComponent()
});

@ -23,8 +23,6 @@ import zone.themcgamer.core.account.command.rank.arguments.ListArgument;
import zone.themcgamer.core.account.command.rank.arguments.SetArgument;
import zone.themcgamer.core.account.event.AccountLoadEvent;
import zone.themcgamer.core.account.event.AccountUnloadEvent;
import zone.themcgamer.core.command.impl.social.MessageCommand;
import zone.themcgamer.core.command.impl.social.ReplyCommand;
import zone.themcgamer.core.common.MojangUtils;
import zone.themcgamer.core.common.Style;
import zone.themcgamer.core.module.Module;
@ -99,8 +97,6 @@ public class AccountManager extends Module {
registerCommand(new GoldCommand(this));
registerCommand(new GemsCommand(this));
registerCommand(new MessageCommand(this, cacheRepository));
registerCommand(new ReplyCommand(this, cacheRepository));
registerCommand(new PlayerInfoCommand(this, cacheRepository));
registerCommand(new zone.themcgamer.core.command.impl.staff.StaffChatCommand());

@ -16,6 +16,8 @@ import zone.themcgamer.core.badSportSystem.BadSportSystem;
import zone.themcgamer.core.badSportSystem.Punishment;
import zone.themcgamer.core.badSportSystem.PunishmentCategory;
import zone.themcgamer.core.chat.command.ClearChatCommand;
import zone.themcgamer.core.chat.command.message.MessageCommand;
import zone.themcgamer.core.chat.command.message.ReplyCommand;
import zone.themcgamer.core.chat.component.IChatComponent;
import zone.themcgamer.core.common.Style;
import zone.themcgamer.core.cooldown.CooldownHandler;
@ -41,11 +43,13 @@ public class ChatManager extends Module {
emotes.put("unflip", "┬─┬ ( ゜-゜ノ)");
}
public ChatManager(JavaPlugin plugin, BadSportSystem badSportSystem, IChatComponent[] chatComponents) {
public ChatManager(JavaPlugin plugin, AccountManager accountManager, BadSportSystem badSportSystem, IChatComponent[] chatComponents) {
super(plugin);
this.badSportSystem = badSportSystem;
this.chatComponents = chatComponents;
registerCommand(new ClearChatCommand());
registerCommand(new MessageCommand(accountManager, badSportSystem));
registerCommand(new ReplyCommand(accountManager, badSportSystem));
/* TODO
/chatmanager blackwords add <word>

@ -1,10 +1,14 @@
package zone.themcgamer.core.command.impl.social;
package zone.themcgamer.core.chat.command.message;
import com.cryptomorin.xseries.XSound;
import lombok.AllArgsConstructor;
import org.bukkit.entity.Player;
import zone.themcgamer.core.account.Account;
import zone.themcgamer.core.account.AccountManager;
import zone.themcgamer.core.badSportSystem.BadSportClient;
import zone.themcgamer.core.badSportSystem.BadSportSystem;
import zone.themcgamer.core.badSportSystem.Punishment;
import zone.themcgamer.core.badSportSystem.PunishmentCategory;
import zone.themcgamer.core.command.Command;
import zone.themcgamer.core.command.CommandProvider;
import zone.themcgamer.core.common.Style;
@ -12,6 +16,7 @@ import zone.themcgamer.data.jedis.cache.CacheRepository;
import zone.themcgamer.data.jedis.cache.impl.PlayerStatusCache;
import zone.themcgamer.data.jedis.command.JedisCommandHandler;
import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent;
import zone.themcgamer.data.jedis.repository.RedisRepository;
import java.util.Arrays;
import java.util.Optional;
@ -20,20 +25,31 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class MessageCommand {
private final AccountManager accountManager;
private final CacheRepository cacheRepository;
private final BadSportSystem badSportSystem;
@Command(name = "msg", aliases = { "whisper", "m", "message", "dm", "w" }, description = "Sent a private message to a player.",
playersOnly = true)
public void onCommand(CommandProvider command) {
Player player = command.getPlayer();
CacheRepository cacheRepository = RedisRepository.getRepository(CacheRepository.class).orElse(null);
if (cacheRepository == null)
return;
Optional<BadSportClient> optionalBadSportClient = badSportSystem.lookup(player.getUniqueId());
if (optionalBadSportClient.isEmpty())
return;
String[] args = command.getArgs();
if (args.length < 2) {
player.sendMessage(Style.main("Chat", "&7Please use &b/" + command.getLabel() + " (player) (message)"));
player.sendMessage(Style.error("Chat", "Usage: &b/" + command.getLabel() + " (player) (message)"));
return;
}
Optional<Punishment> optionalMute = optionalBadSportClient.get().getMute();
if (optionalMute.isPresent()) {
player.sendMessage(Style.error("Bad Sport", PunishmentCategory.format(optionalMute.get())));
return;
}
String target = args[0];
if (player.getName().equalsIgnoreCase(target)) {
player.sendMessage(Style.main("Chat", "&7You can not message yourself."));
player.sendMessage(Style.error("Chat", "You can not message yourself."));
return;
}
String message = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));

@ -1,10 +1,14 @@
package zone.themcgamer.core.command.impl.social;
package zone.themcgamer.core.chat.command.message;
import com.cryptomorin.xseries.XSound;
import lombok.RequiredArgsConstructor;
import org.bukkit.entity.Player;
import zone.themcgamer.core.account.Account;
import zone.themcgamer.core.account.AccountManager;
import zone.themcgamer.core.badSportSystem.BadSportClient;
import zone.themcgamer.core.badSportSystem.BadSportSystem;
import zone.themcgamer.core.badSportSystem.Punishment;
import zone.themcgamer.core.badSportSystem.PunishmentCategory;
import zone.themcgamer.core.command.Command;
import zone.themcgamer.core.command.CommandProvider;
import zone.themcgamer.core.common.Style;
@ -12,6 +16,7 @@ import zone.themcgamer.data.jedis.cache.CacheRepository;
import zone.themcgamer.data.jedis.cache.impl.PlayerStatusCache;
import zone.themcgamer.data.jedis.command.JedisCommandHandler;
import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent;
import zone.themcgamer.data.jedis.repository.RedisRepository;
import java.util.Arrays;
import java.util.Optional;
@ -20,16 +25,27 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class ReplyCommand {
private final AccountManager accountManager;
private final CacheRepository cacheRepository;
private final BadSportSystem badSportSystem;
@Command(name = "reply", aliases = { "r" }, description = "Reply to a player that sent you a private message.", playersOnly = true)
public void onCommand(CommandProvider command) {
Player player = command.getPlayer();
CacheRepository cacheRepository = RedisRepository.getRepository(CacheRepository.class).orElse(null);
if (cacheRepository == null)
return;
String[] args = command.getArgs();
if (args.length < 1) {
player.sendMessage(Style.main("Chat", "&7Please use &b/" + command.getLabel() + " (message)"));
return;
}
Optional<BadSportClient> optionalBadSportClient = badSportSystem.lookup(player.getUniqueId());
if (optionalBadSportClient.isEmpty())
return;
Optional<Punishment> optionalMute = optionalBadSportClient.get().getMute();
if (optionalMute.isPresent()) {
player.sendMessage(Style.error("Bad Sport", PunishmentCategory.format(optionalMute.get())));
return;
}
String message = Arrays.stream(args).skip(0).collect(Collectors.joining(" "));
Optional<PlayerStatusCache> optionalPlayerStatusCache = cacheRepository.lookup(PlayerStatusCache.class, player.getUniqueId());
if (optionalPlayerStatusCache.isEmpty()) {

@ -50,6 +50,7 @@ public abstract class MGZPlugin extends JavaPlugin {
protected MySQLController mySQLController;
protected CommandManager commandManager;
protected ServerTraveler traveler;
protected AccountManager accountManager;
protected BadSportSystem badSportSystem;
protected NametagManager nametagManager;
@ -169,7 +170,7 @@ public abstract class MGZPlugin extends JavaPlugin {
new CooldownHandler(this);
nametagManager = new NametagManager(this);
AccountManager accountManager = new AccountManager(this, mySQLController, nametagManager);
accountManager = new AccountManager(this, mySQLController, nametagManager);
traveler = new ServerTraveler(this);
new ServerUpdater(this, traveler);
new ServerManager(this, traveler);

@ -50,7 +50,7 @@ public class Hub extends MGZPlugin {
new WorldListener(this);
new ScoreboardHandler(this, HubScoreboard.class, 3L);
new ChatManager(this, badSportSystem, new IChatComponent[] {
new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] {
new BasicRankComponent(),
new BasicNameComponent()
});

@ -34,7 +34,7 @@ public class Skyblock extends MGZPlugin {
new PlayerListener(this);
new ScoreboardHandler(this, SkyblockScoreboard.class, 3L);
new ChatManager(this, badSportSystem, new IChatComponent[] {
new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] {
new SkyblockChatLevelComponent(),
new BasicRankComponent(),
new BasicNameComponent()