Add AntiSpam front end
This commit is contained in:
parent
4562b00dcb
commit
a744566cd3
@ -1,23 +1,30 @@
|
||||
package mineplex.core.common.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
/**
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public class ApiEndpoint
|
||||
{
|
||||
private static final String API_HOST = "10.33.53.12";
|
||||
// private static final String API_HOST = "localhost";
|
||||
// private static final int API_PORT = 3000;
|
||||
private static final int API_PORT = 7979;
|
||||
|
||||
private Gson _gson;
|
||||
private ApiWebCall _webCall;
|
||||
|
||||
public ApiEndpoint(String path, Gson gson)
|
||||
public ApiEndpoint(ApiHost host, String path)
|
||||
{
|
||||
String url = "http://" + API_HOST + ":" + API_PORT + path;
|
||||
this(host, path, new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create());
|
||||
}
|
||||
|
||||
public ApiEndpoint(ApiHost host, String path, Gson gson)
|
||||
{
|
||||
this(host.getHost(), host.getPort(), path, gson);
|
||||
}
|
||||
|
||||
public ApiEndpoint(String host, int port, String path, Gson gson)
|
||||
{
|
||||
String url = "http://" + host + ":" + port + path;
|
||||
_webCall = new ApiWebCall(url, gson);
|
||||
_gson = gson;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package mineplex.core.common.api;
|
||||
|
||||
/**
|
||||
* TODO: Store this in a file instead of being hardcoded
|
||||
*
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public enum ApiHost
|
||||
{
|
||||
AMPLIFIERS("10.33.53.12", 7979),
|
||||
ANTISPAM("10.33.53.12", 8181);
|
||||
|
||||
private String _host;
|
||||
private int _port;
|
||||
|
||||
ApiHost(String host, int port)
|
||||
{
|
||||
_host = host;
|
||||
_port = port;
|
||||
}
|
||||
|
||||
public String getHost()
|
||||
{
|
||||
return _host;
|
||||
}
|
||||
|
||||
public int getPort()
|
||||
{
|
||||
return _port;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package mineplex.core.antispam;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.antispam.repository.AntiSpamRepository;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public class AntiSpamManager extends MiniPlugin
|
||||
{
|
||||
private final String _pluginName;
|
||||
private final AntiSpamRepository _repository;
|
||||
|
||||
public AntiSpamManager()
|
||||
{
|
||||
super("AntiSpam");
|
||||
|
||||
_pluginName = getPlugin().getClass().getSimpleName();
|
||||
_repository = new AntiSpamRepository();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
// Only listen to async events, as non async events are fake messages
|
||||
if (event.isAsynchronous())
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
String message = event.getMessage();
|
||||
ChatPayload payload = new ChatPayload(player.getName(), player.getUniqueId().toString(), message);
|
||||
// Run our API call async to the chat message (prevents blocking chat message)
|
||||
runAsync(() -> _repository.logMessage(_pluginName, payload));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package mineplex.core.antispam;
|
||||
|
||||
/**
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public class ChatPayload
|
||||
{
|
||||
private String _playerName;
|
||||
private String _uuid;
|
||||
private String _message;
|
||||
|
||||
public ChatPayload(String playerName, String uuid, String message)
|
||||
{
|
||||
_playerName = playerName;
|
||||
_uuid = uuid;
|
||||
_message = message;
|
||||
}
|
||||
|
||||
public String getPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public String getUuid()
|
||||
{
|
||||
return _uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid)
|
||||
{
|
||||
_uuid = uuid;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
{
|
||||
return _message;
|
||||
}
|
||||
|
||||
public void setMessage(String message)
|
||||
{
|
||||
_message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package mineplex.core.antispam.repository;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import mineplex.core.antispam.ChatPayload;
|
||||
import mineplex.core.common.api.ApiEndpoint;
|
||||
import mineplex.core.common.api.ApiHost;
|
||||
import mineplex.core.common.api.ApiResponse;
|
||||
import mineplex.core.thread.ThreadPool;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public class AntiSpamRepository extends ApiEndpoint
|
||||
{
|
||||
public AntiSpamRepository()
|
||||
{
|
||||
super(ApiHost.ANTISPAM, "/chat");
|
||||
}
|
||||
|
||||
public ApiResponse logMessage(String source, ChatPayload payload)
|
||||
{
|
||||
return getWebCall().post("/" + source, ApiResponse.class, payload);
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import mineplex.core.common.api.ApiEndpoint;
|
||||
import mineplex.core.common.api.ApiFieldNamingStrategy;
|
||||
import mineplex.core.common.api.ApiHost;
|
||||
import mineplex.core.common.api.ApiResponse;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -23,7 +24,7 @@ public class BoosterRepository extends ApiEndpoint
|
||||
{
|
||||
public BoosterRepository()
|
||||
{
|
||||
super("/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
|
||||
super(ApiHost.AMPLIFIERS, "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
|
||||
// .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create());
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
import mineplex.core.antispam.AntiSpamManager;
|
||||
import mineplex.core.aprilfools.AprilFoolsManager;
|
||||
import mineplex.core.benefit.BenefitManager;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
@ -206,6 +207,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
new SoccerManager(this, _gadgetManager);
|
||||
new KothManager(this, _gadgetManager);
|
||||
|
||||
new AntiSpamManager();
|
||||
|
||||
//new TrickOrTreatManager(_plugin, this, taskManager, donationManager, clientManager);
|
||||
|
||||
_petManager = petManager;
|
||||
|
Loading…
Reference in New Issue
Block a user