Add more features and improve multiserver compatability

This commit is contained in:
Ghoti 2019-03-03 12:56:49 -06:00
parent 653d332f31
commit 87eac4114f
7 changed files with 68 additions and 28 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId> <groupId>com.fpghoti</groupId>
<artifactId>BCraftBot</artifactId> <artifactId>BCraftBot</artifactId>
<version>1.0</version> <version>1.1</version>
<build> <build>
<resources> <resources>
<resource> <resource>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId> <groupId>com.fpghoti</groupId>
<artifactId>BCraftBot</artifactId> <artifactId>BCraftBot</artifactId>
<version>1.0</version> <version>1.1</version>
<repositories> <repositories>
<repository> <repository>
<id>jcenter</id> <id>jcenter</id>

View File

@ -35,6 +35,9 @@ public class Main extends JavaPlugin {
private boolean stopTimer = false; private boolean stopTimer = false;
private boolean assignrole = false; private boolean assignrole = false;
private boolean checkrole = false; private boolean checkrole = false;
private boolean outputtodiscord = false;
private boolean mainrecordkeeper = false;
private int mysqlTimer = 1140; private int mysqlTimer = 1140;
@ -115,7 +118,7 @@ public class Main extends JavaPlugin {
FileConfiguration config = this.getConfig(); FileConfiguration config = this.getConfig();
public void messageSet(){ public void messageSet(){
config.options().header("If CheckRole is true, users will need the Discord role listed in RequiredRole to join the server. AssignRole tells the bot whether or not it should give users the role specified in RoleName upon joining the server.\nIf you wish to limit the bot commands to a specific channel, edit its permissions accordingly."); config.options().header("If CheckRole is true, users will need the Discord role listed in RequiredRole to join the server. AssignRole tells the bot whether or not it should give users the role specified in RoleName upon joining the server.\nIf you wish to limit the bot commands to a specific channel, edit its permissions accordingly.\nMainRecordKeeper tells the bot if it is the main record keeper. If you are using the same database for multiple servers, you will only want one bot to insert new users into the database.");
if (config.get("Host") == null){ if (config.get("Host") == null){
config.createSection("Host"); config.createSection("Host");
config.set("Host", "0.0.0.0"); config.set("Host", "0.0.0.0");
@ -172,6 +175,14 @@ public class Main extends JavaPlugin {
config.createSection("RoleName"); config.createSection("RoleName");
config.set("RoleName", "Craftee"); config.set("RoleName", "Craftee");
} }
if (config.get("OutputToDiscord") == null){
config.createSection("OutputToDiscord");
config.set("OutputToDiscord", true);
}
if (config.get("MainRecordKeeper") == null){
config.createSection("MainRecordKeeper");
config.set("MainRecordKeeper", true);
}
this.saveConfig(); this.saveConfig();
} }
@ -189,6 +200,8 @@ public class Main extends JavaPlugin {
kickmsg = config.getString("KickMessage"); kickmsg = config.getString("KickMessage");
assignrole = config.getBoolean("AssignRole"); assignrole = config.getBoolean("AssignRole");
rolename = config.getString("RoleName"); rolename = config.getString("RoleName");
outputtodiscord = config.getBoolean("OutputToDiscord");
mainrecordkeeper = config.getBoolean("MainRecordKeeper");
} }
public void setExemptList(String s) { public void setExemptList(String s) {
@ -250,6 +263,14 @@ public class Main extends JavaPlugin {
return sql; return sql;
} }
public boolean outputToDiscord() {
return outputtodiscord;
}
public boolean mainRecordKeeper() {
return mainrecordkeeper;
}
public boolean isMember(Player p) { public boolean isMember(Player p) {
String name = p.getName().toLowerCase(); String name = p.getName().toLowerCase();
ArrayList<String> ids = new ArrayList<String>(); ArrayList<String> ids = new ArrayList<String>();

View File

@ -87,4 +87,8 @@ public class ServerBot {
jda.shutdownNow(); jda.shutdownNow();
} }
public Main getPlugin() {
return plugin;
}
} }

View File

@ -31,13 +31,21 @@ public class AddMeCommand implements Command{
return; return;
} }
bot.log(Level.INFO, event.getAuthor().getName() + " issued a Discord Bot command: !addme " + name); bot.log(Level.INFO, event.getAuthor().getName() + " issued a Discord Bot command: !addme " + name);
if(bot.getPlugin().mainRecordKeeper()) {
if(bot.getSQL().itemExists("DiscordID", event.getAuthor().getId(), bot.getTableName())) { if(bot.getSQL().itemExists("DiscordID", event.getAuthor().getId(), bot.getTableName())) {
bot.getSQL().set("MinecraftName", name, "DiscordID", "=", event.getAuthor().getId(), bot.getTableName()); bot.getSQL().set("MinecraftName", name, "DiscordID", "=", event.getAuthor().getId(), bot.getTableName());
}else { }else {
bot.getSQL().update("INSERT INTO " + bot.getTableName() + " (DiscordID,MinecraftName) VALUES (\'" + event.getAuthor().getId() + "\',\'" + name + "\');"); bot.getSQL().update("INSERT INTO " + bot.getTableName() + " (DiscordID,MinecraftName) VALUES (\'" + event.getAuthor().getId() + "\',\'" + name + "\');");
} }
}
if(bot.getPlugin().outputToDiscord()) {
event.getChannel().sendMessage("Updating Minecraft user database with username **" + args[0] + "**.").queue(); event.getChannel().sendMessage("Updating Minecraft user database with username **" + args[0] + "**.").queue();
} }
}
} }

View File

@ -25,6 +25,10 @@ public class PlayerListener implements Listener {
public void onPlayerLogin(PlayerLoginEvent event){ public void onPlayerLogin(PlayerLoginEvent event){
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasPermission("bcraftbot.bypasscheck")) {
return;
}
if(!plugin.isMember(player) && !plugin.isExempt(player.getName())) { if(!plugin.isMember(player) && !plugin.isExempt(player.getName())) {
event.disallow(Result.KICK_OTHER, plugin.getKickMessage()); event.disallow(Result.KICK_OTHER, plugin.getKickMessage());
return; return;
@ -32,11 +36,14 @@ public class PlayerListener implements Listener {
if(plugin.checkRole() && !plugin.isExempt(player.getName())) { if(plugin.checkRole() && !plugin.isExempt(player.getName())) {
boolean allow = false; boolean allow = false;
for(Guild guild : plugin.getBot().getJDA().getGuilds()) { for(Guild guild : plugin.getBot().getJDA().getGuilds()) {
for(String rolename : plugin.getRequiredRole().split(",")) {
Role role = null; Role role = null;
for(Role r : guild.getRoles()) { for(Role r : guild.getRoles()) {
if(r.getName().equalsIgnoreCase(plugin.getRequiredRole())) { if(r.getName().equalsIgnoreCase(rolename)) {
role = r; role = r;
} }
} }
@ -49,7 +56,7 @@ public class PlayerListener implements Listener {
allow = true; allow = true;
} }
} }
}
} }
if(!allow) { if(!allow) {

View File

@ -1,5 +1,5 @@
main: com.fpghoti.bcraftbot.Main main: com.fpghoti.bcraftbot.Main
version: 1.0 version: 1.1
api-version: 1.13 api-version: 1.13
name: BCraftBot name: BCraftBot
descripion: Discord-based whitelisting system for Minecraft descripion: Discord-based whitelisting system for Minecraft