Merge pull request #10 from nickreesdev/master

Made it so muted players can't use /message and or /reply
This commit is contained in:
Braydon 2021-02-20 13:28:49 -05:00 committed by GitHub
commit 6e983ae807
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 ScoreboardHandler(this, ArcadeScoreboard.class, 3L);
new ChatManager(this, badSportSystem, new IChatComponent[] { new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] {
new BasicRankComponent(), new BasicRankComponent(),
new BasicNameComponent() new BasicNameComponent()
}); });

@ -33,7 +33,7 @@ public class Build extends MGZPlugin {
WorldManager worldManager = new WorldManager(this); WorldManager worldManager = new WorldManager(this);
new PlayerListener(this, worldManager); new PlayerListener(this, worldManager);
new ChatManager(this, badSportSystem, new IChatComponent[] { new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] {
new BasicRankComponent(), new BasicRankComponent(),
new BasicNameComponent() 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.command.rank.arguments.SetArgument;
import zone.themcgamer.core.account.event.AccountLoadEvent; import zone.themcgamer.core.account.event.AccountLoadEvent;
import zone.themcgamer.core.account.event.AccountUnloadEvent; 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.MojangUtils;
import zone.themcgamer.core.common.Style; import zone.themcgamer.core.common.Style;
import zone.themcgamer.core.module.Module; import zone.themcgamer.core.module.Module;
@ -99,8 +97,6 @@ public class AccountManager extends Module {
registerCommand(new GoldCommand(this)); registerCommand(new GoldCommand(this));
registerCommand(new GemsCommand(this)); registerCommand(new GemsCommand(this));
registerCommand(new MessageCommand(this, cacheRepository));
registerCommand(new ReplyCommand(this, cacheRepository));
registerCommand(new PlayerInfoCommand(this, cacheRepository)); registerCommand(new PlayerInfoCommand(this, cacheRepository));
registerCommand(new zone.themcgamer.core.command.impl.staff.StaffChatCommand()); 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.Punishment;
import zone.themcgamer.core.badSportSystem.PunishmentCategory; import zone.themcgamer.core.badSportSystem.PunishmentCategory;
import zone.themcgamer.core.chat.command.ClearChatCommand; 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.chat.component.IChatComponent;
import zone.themcgamer.core.common.Style; import zone.themcgamer.core.common.Style;
import zone.themcgamer.core.cooldown.CooldownHandler; import zone.themcgamer.core.cooldown.CooldownHandler;
@ -41,11 +43,13 @@ public class ChatManager extends Module {
emotes.put("unflip", "┬─┬ ( ゜-゜ノ)"); emotes.put("unflip", "┬─┬ ( ゜-゜ノ)");
} }
public ChatManager(JavaPlugin plugin, BadSportSystem badSportSystem, IChatComponent[] chatComponents) { public ChatManager(JavaPlugin plugin, AccountManager accountManager, BadSportSystem badSportSystem, IChatComponent[] chatComponents) {
super(plugin); super(plugin);
this.badSportSystem = badSportSystem; this.badSportSystem = badSportSystem;
this.chatComponents = chatComponents; this.chatComponents = chatComponents;
registerCommand(new ClearChatCommand()); registerCommand(new ClearChatCommand());
registerCommand(new MessageCommand(accountManager, badSportSystem));
registerCommand(new ReplyCommand(accountManager, badSportSystem));
/* TODO /* TODO
/chatmanager blackwords add <word> /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 com.cryptomorin.xseries.XSound;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import zone.themcgamer.core.account.Account; import zone.themcgamer.core.account.Account;
import zone.themcgamer.core.account.AccountManager; 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.Command;
import zone.themcgamer.core.command.CommandProvider; import zone.themcgamer.core.command.CommandProvider;
import zone.themcgamer.core.common.Style; 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.cache.impl.PlayerStatusCache;
import zone.themcgamer.data.jedis.command.JedisCommandHandler; import zone.themcgamer.data.jedis.command.JedisCommandHandler;
import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent; import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent;
import zone.themcgamer.data.jedis.repository.RedisRepository;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
@ -20,20 +25,31 @@ import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
public class MessageCommand { public class MessageCommand {
private final AccountManager accountManager; 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.", @Command(name = "msg", aliases = { "whisper", "m", "message", "dm", "w" }, description = "Sent a private message to a player.",
playersOnly = true) playersOnly = true)
public void onCommand(CommandProvider command) { public void onCommand(CommandProvider command) {
Player player = command.getPlayer(); 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(); String[] args = command.getArgs();
if (args.length < 2) { 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; return;
} }
String target = args[0]; String target = args[0];
if (player.getName().equalsIgnoreCase(target)) { 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; return;
} }
String message = Arrays.stream(args).skip(1).collect(Collectors.joining(" ")); 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 com.cryptomorin.xseries.XSound;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import zone.themcgamer.core.account.Account; import zone.themcgamer.core.account.Account;
import zone.themcgamer.core.account.AccountManager; 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.Command;
import zone.themcgamer.core.command.CommandProvider; import zone.themcgamer.core.command.CommandProvider;
import zone.themcgamer.core.common.Style; 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.cache.impl.PlayerStatusCache;
import zone.themcgamer.data.jedis.command.JedisCommandHandler; import zone.themcgamer.data.jedis.command.JedisCommandHandler;
import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent; import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent;
import zone.themcgamer.data.jedis.repository.RedisRepository;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
@ -20,16 +25,27 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ReplyCommand { public class ReplyCommand {
private final AccountManager accountManager; 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) @Command(name = "reply", aliases = { "r" }, description = "Reply to a player that sent you a private message.", playersOnly = true)
public void onCommand(CommandProvider command) { public void onCommand(CommandProvider command) {
Player player = command.getPlayer(); Player player = command.getPlayer();
CacheRepository cacheRepository = RedisRepository.getRepository(CacheRepository.class).orElse(null);
if (cacheRepository == null)
return;
String[] args = command.getArgs(); String[] args = command.getArgs();
if (args.length < 1) { if (args.length < 1) {
player.sendMessage(Style.main("Chat", "&7Please use &b/" + command.getLabel() + " (message)")); player.sendMessage(Style.main("Chat", "&7Please use &b/" + command.getLabel() + " (message)"));
return; 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(" ")); String message = Arrays.stream(args).skip(0).collect(Collectors.joining(" "));
Optional<PlayerStatusCache> optionalPlayerStatusCache = cacheRepository.lookup(PlayerStatusCache.class, player.getUniqueId()); Optional<PlayerStatusCache> optionalPlayerStatusCache = cacheRepository.lookup(PlayerStatusCache.class, player.getUniqueId());
if (optionalPlayerStatusCache.isEmpty()) { if (optionalPlayerStatusCache.isEmpty()) {

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

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

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