Added abot module
This commit is contained in:
parent
29689d51cc
commit
d9746526ca
@ -6,6 +6,7 @@ import com.redstoner.annotations.Version;
|
||||
import com.redstoner.coremods.debugger.Debugger;
|
||||
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
||||
import com.redstoner.misc.mysql.MysqlHandler;
|
||||
import com.redstoner.modules.abot.Abot;
|
||||
import com.redstoner.modules.adminchat.Adminchat;
|
||||
import com.redstoner.modules.adminnotes.AdminNotes;
|
||||
import com.redstoner.modules.chatgroups.Chatgroups;
|
||||
@ -23,7 +24,7 @@ import com.redstoner.modules.webtoken.WebToken;
|
||||
/** Main class. Duh.
|
||||
*
|
||||
* @author Pepich */
|
||||
@Version(major = 1, minor = 3, revision = 1, compatible = -1)
|
||||
@Version(major = 1, minor = 3, revision = 3, compatible = -1)
|
||||
public class Main extends JavaPlugin
|
||||
{
|
||||
public static JavaPlugin plugin;
|
||||
@ -35,7 +36,7 @@ public class Main extends JavaPlugin
|
||||
Debugger.init();
|
||||
ModuleLoader.init();
|
||||
MysqlHandler.init();
|
||||
// TODO: ModuleLoader.addModule(Answerbot.class);
|
||||
ModuleLoader.addModule(Abot.class);
|
||||
ModuleLoader.addModule(Adminchat.class);
|
||||
ModuleLoader.addModule(AdminNotes.class);
|
||||
// TODO: ModuleLoader.addModule(Chatalias.class);
|
||||
|
92
src/com/redstoner/modules/abot/Abot.java
Normal file
92
src/com/redstoner/modules/abot/Abot.java
Normal file
@ -0,0 +1,92 @@
|
||||
package com.redstoner.modules.abot;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
import com.redstoner.annotations.AutoRegisterListener;
|
||||
import com.redstoner.annotations.Version;
|
||||
import com.redstoner.misc.JsonManager;
|
||||
import com.redstoner.misc.Main;
|
||||
import com.redstoner.misc.Utils;
|
||||
import com.redstoner.modules.Module;
|
||||
|
||||
@AutoRegisterListener
|
||||
@Version(major = 1, minor = 0, revision = 0, compatible = 1)
|
||||
public class Abot implements Module, Listener
|
||||
{
|
||||
private boolean enabled = false;
|
||||
private File answerFile = new File(Main.plugin.getDataFolder(), "abot.json");
|
||||
JSONArray answers;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
for (Object rawObject : answers)
|
||||
{
|
||||
JSONObject entry = (JSONObject) rawObject;
|
||||
JSONArray regexes = (JSONArray) entry.get("regex");
|
||||
for (Object regex : regexes)
|
||||
{
|
||||
if (event.getMessage().toLowerCase().matches((String) regex))
|
||||
{
|
||||
Object hideperm = entry.get("hide-perm");
|
||||
if (hideperm == null || !event.getPlayer().hasPermission((String) hideperm))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(event.getPlayer(), null, (String) entry.get("message"), '&');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(hook = "abot_reload")
|
||||
public void loadAnswers(CommandSender sender)
|
||||
{
|
||||
answers = JsonManager.getArray(answerFile);
|
||||
if (answers == null)
|
||||
answers = new JSONArray();
|
||||
Utils.sendMessage(sender, null, "Loaded the abot.json file!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
loadAnswers(Bukkit.getConsoleSender());
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// @noformat
|
||||
@Override
|
||||
public String getCommandString()
|
||||
{
|
||||
return "command abot {\n" +
|
||||
" reload {" +
|
||||
" help Reloads answes from the .json file.;\n" +
|
||||
" run abot_reload;\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
}
|
||||
// format
|
||||
}
|
Reference in New Issue
Block a user