Merge branch 'feature/shadowmute' into develop
This commit is contained in:
commit
55086efd91
@ -0,0 +1,21 @@
|
||||
package mineplex.core.antispam;
|
||||
|
||||
import mineplex.core.common.api.ApiResponse;
|
||||
|
||||
/**
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public class AntiSpamApiResponse extends ApiResponse
|
||||
{
|
||||
private boolean isShadowMuted;
|
||||
|
||||
public AntiSpamApiResponse()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public boolean isShadowMuted()
|
||||
{
|
||||
return isShadowMuted;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package mineplex.core.antispam;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.antispam.repository.AntiSpamRepository;
|
||||
import mineplex.core.chat.IChatMessageFormatter;
|
||||
import mineplex.core.status.ServerStatusManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -18,6 +19,8 @@ public class AntiSpamManager extends MiniPlugin
|
||||
private final String _region;
|
||||
private final AntiSpamRepository _repository;
|
||||
|
||||
private IChatMessageFormatter _messageFormatter;
|
||||
|
||||
public AntiSpamManager()
|
||||
{
|
||||
super("AntiSpam");
|
||||
@ -38,6 +41,11 @@ public class AntiSpamManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessageFormatter(IChatMessageFormatter messageFormatter)
|
||||
{
|
||||
_messageFormatter = messageFormatter;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
@ -48,7 +56,19 @@ public class AntiSpamManager extends MiniPlugin
|
||||
String message = event.getMessage();
|
||||
ChatPayload payload = new ChatPayload(player.getName(), player.getUniqueId().toString(), _region, _serverName, message, System.currentTimeMillis());
|
||||
// Run our API call async to the chat message (prevents blocking chat message)
|
||||
runAsync(() -> _repository.logMessage(_pluginName, payload));
|
||||
AntiSpamApiResponse response = _repository.sendMessage(_pluginName, payload);
|
||||
if (response != null) // can be null if the request times out
|
||||
{
|
||||
if (response.isShadowMuted())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if (_messageFormatter != null)
|
||||
{
|
||||
String formattedMessage = String.format(_messageFormatter.getChatFormat(player, message).getFormat(), player.getName(), message);
|
||||
event.getPlayer().sendMessage(formattedMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mineplex.core.antispam.repository;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import mineplex.core.antispam.AntiSpamApiResponse;
|
||||
import mineplex.core.antispam.ChatPayload;
|
||||
import mineplex.core.common.api.ApiEndpoint;
|
||||
import mineplex.core.common.api.ApiHost;
|
||||
@ -19,8 +20,8 @@ public class AntiSpamRepository extends ApiEndpoint
|
||||
super(ApiHost.ANTISPAM, "/chat");
|
||||
}
|
||||
|
||||
public ApiResponse logMessage(String source, ChatPayload payload)
|
||||
public AntiSpamApiResponse sendMessage(String source, ChatPayload payload)
|
||||
{
|
||||
return getWebCall().post("/" + source, ApiResponse.class, payload);
|
||||
return getWebCall().post("/" + source, AntiSpamApiResponse.class, payload);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package mineplex.core.chat;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
import mineplex.core.antispam.AntiSpamManager;
|
||||
import mineplex.core.chat.command.BroadcastCommand;
|
||||
import mineplex.core.chat.command.ChatSlowCommand;
|
||||
import mineplex.core.chat.command.SilenceCommand;
|
||||
|
39
Plugins/Mineplex.Core/src/mineplex/core/chat/ChatFormat.java
Normal file
39
Plugins/Mineplex.Core/src/mineplex/core/chat/ChatFormat.java
Normal file
@ -0,0 +1,39 @@
|
||||
package mineplex.core.chat;
|
||||
|
||||
/**
|
||||
* The format for a chat message being sent by a player
|
||||
*
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public class ChatFormat
|
||||
{
|
||||
private String _format;
|
||||
private boolean _json;
|
||||
|
||||
public ChatFormat(String format, boolean json)
|
||||
{
|
||||
_format = format;
|
||||
_json = json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string representing the chat format. This will be represented as a JSON string if {@link #isJson()},
|
||||
* or should be in the standard Spigot chat format otherwise.
|
||||
*
|
||||
* @return A string representing how to format the chat message
|
||||
*/
|
||||
public String getFormat()
|
||||
{
|
||||
return _format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this chat format a JSON string (should be sent to player as a json message)
|
||||
*
|
||||
* @return boolean representing if this chat format is in the json format
|
||||
*/
|
||||
public boolean isJson()
|
||||
{
|
||||
return _json;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package mineplex.core.chat;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* This is an interface that provides a method to format chat message.
|
||||
* Needed for AntiSpam's shadow mute feature.
|
||||
*
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public interface IChatMessageFormatter
|
||||
{
|
||||
/**
|
||||
* Returns the proper format for the chat message to be sent
|
||||
*
|
||||
* @param player Player sending the message
|
||||
* @param message The message the player is trying to send
|
||||
* @return the format of the chat message,
|
||||
*/
|
||||
public ChatFormat getChatFormat(Player player, String message);
|
||||
}
|
@ -14,6 +14,8 @@ import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.bonuses.BonusManager;
|
||||
import mineplex.core.boosters.BoosterManager;
|
||||
import mineplex.core.botspam.BotSpamManager;
|
||||
import mineplex.core.chat.ChatFormat;
|
||||
import mineplex.core.chat.IChatMessageFormatter;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
@ -120,7 +122,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* Main manager for clans hub
|
||||
*/
|
||||
public class HubManager extends MiniPlugin
|
||||
public class HubManager extends MiniPlugin implements IChatMessageFormatter
|
||||
{
|
||||
private BlockRestore _blockRestore;
|
||||
private CoreClientManager _clientManager;
|
||||
@ -527,6 +529,33 @@ public class HubManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatFormat getChatFormat(Player player, String message)
|
||||
{
|
||||
Rank rank = GetClients().Get(player).getRealOrDisguisedRank();
|
||||
|
||||
//Level Prefix
|
||||
String levelStr = _achievementManager.getMineplexLevel(player, rank);
|
||||
|
||||
//Rank Prefix
|
||||
String rankStr = "";
|
||||
if (rank != Rank.ALL)
|
||||
rankStr = rank.getTag(true, true) + " ";
|
||||
|
||||
TextComponent rankComponent = new TextComponent(rankStr);
|
||||
TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + "%1$s");
|
||||
TextComponent component = new TextComponent();
|
||||
|
||||
rankComponent.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(rank.getColor() + rank.getTag(true, true) + ChatColor.WHITE + "\n" + rank.getDescription()).create()));
|
||||
|
||||
component.setText(levelStr);
|
||||
component.addExtra(rankComponent);
|
||||
component.addExtra(playerNameText);
|
||||
component.addExtra(" " + ChatColor.WHITE + "%2$s");
|
||||
|
||||
return new ChatFormat(component.toLegacyText(), false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void Damage(EntityDamageEvent event)
|
||||
{
|
||||
|
@ -12,6 +12,8 @@ import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.bonuses.BonusManager;
|
||||
import mineplex.core.boosters.BoosterManager;
|
||||
import mineplex.core.botspam.BotSpamManager;
|
||||
import mineplex.core.chat.ChatFormat;
|
||||
import mineplex.core.chat.IChatMessageFormatter;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
@ -137,7 +139,7 @@ import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HubManager extends MiniClientPlugin<HubClient>
|
||||
public class HubManager extends MiniClientPlugin<HubClient> implements IChatMessageFormatter
|
||||
{
|
||||
// ☃❅ Snowman!
|
||||
public HubType Type = HubType.Normal;
|
||||
@ -235,9 +237,10 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
new SoccerManager(this, _gadgetManager);
|
||||
new KothManager(this, _gadgetManager);
|
||||
|
||||
new AntiSpamManager();
|
||||
new MenuManager(_plugin);
|
||||
new NewInteractionsManager();
|
||||
AntiSpamManager antiSpam = new AntiSpamManager();
|
||||
antiSpam.setMessageFormatter(this);
|
||||
|
||||
//new TrickOrTreatManager(_plugin, this, taskManager, donationManager, clientManager);
|
||||
|
||||
@ -744,6 +747,33 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatFormat getChatFormat(Player player, String message)
|
||||
{
|
||||
Rank rank = GetClients().Get(player).getRealOrDisguisedRank();
|
||||
|
||||
//Level Prefix
|
||||
String levelStr = _achievementManager.getMineplexLevel(player, rank);
|
||||
|
||||
//Rank Prefix
|
||||
String rankStr = "";
|
||||
if (rank != Rank.ALL)
|
||||
rankStr = rank.getTag(true, true) + " ";
|
||||
|
||||
TextComponent rankComponent = new TextComponent(rankStr);
|
||||
TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + "%1$s");
|
||||
TextComponent component = new TextComponent();
|
||||
|
||||
rankComponent.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(rank.getColor() + rank.getTag(true, true) + ChatColor.WHITE + "\n" + rank.getDescription()).create()));
|
||||
|
||||
component.setText(levelStr);
|
||||
component.addExtra(rankComponent);
|
||||
component.addExtra(playerNameText);
|
||||
component.addExtra(" " + ChatColor.WHITE + "%2$s");
|
||||
|
||||
return new ChatFormat(component.toLegacyText(), false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void Damage(EntityDamageEvent event)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user