Add more features and improve multiserver compatability
This commit is contained in:
parent
653d332f31
commit
87eac4114f
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.fpghoti</groupId>
|
||||
<artifactId>BCraftBot</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.fpghoti</groupId>
|
||||
<artifactId>BCraftBot</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter</id>
|
||||
|
|
|
@ -35,6 +35,9 @@ public class Main extends JavaPlugin {
|
|||
private boolean stopTimer = false;
|
||||
private boolean assignrole = false;
|
||||
private boolean checkrole = false;
|
||||
private boolean outputtodiscord = false;
|
||||
private boolean mainrecordkeeper = false;
|
||||
|
||||
|
||||
private int mysqlTimer = 1140;
|
||||
|
||||
|
@ -115,7 +118,7 @@ public class Main extends JavaPlugin {
|
|||
FileConfiguration config = this.getConfig();
|
||||
|
||||
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){
|
||||
config.createSection("Host");
|
||||
config.set("Host", "0.0.0.0");
|
||||
|
@ -172,6 +175,14 @@ public class Main extends JavaPlugin {
|
|||
config.createSection("RoleName");
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -189,6 +200,8 @@ public class Main extends JavaPlugin {
|
|||
kickmsg = config.getString("KickMessage");
|
||||
assignrole = config.getBoolean("AssignRole");
|
||||
rolename = config.getString("RoleName");
|
||||
outputtodiscord = config.getBoolean("OutputToDiscord");
|
||||
mainrecordkeeper = config.getBoolean("MainRecordKeeper");
|
||||
}
|
||||
|
||||
public void setExemptList(String s) {
|
||||
|
@ -250,6 +263,14 @@ public class Main extends JavaPlugin {
|
|||
return sql;
|
||||
}
|
||||
|
||||
public boolean outputToDiscord() {
|
||||
return outputtodiscord;
|
||||
}
|
||||
|
||||
public boolean mainRecordKeeper() {
|
||||
return mainrecordkeeper;
|
||||
}
|
||||
|
||||
public boolean isMember(Player p) {
|
||||
String name = p.getName().toLowerCase();
|
||||
ArrayList<String> ids = new ArrayList<String>();
|
||||
|
|
|
@ -87,4 +87,8 @@ public class ServerBot {
|
|||
jda.shutdownNow();
|
||||
}
|
||||
|
||||
public Main getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,12 +31,20 @@ public class AddMeCommand implements Command{
|
|||
return;
|
||||
}
|
||||
bot.log(Level.INFO, event.getAuthor().getName() + " issued a Discord Bot command: !addme " + name);
|
||||
if(bot.getSQL().itemExists("DiscordID", event.getAuthor().getId(), bot.getTableName())) {
|
||||
bot.getSQL().set("MinecraftName", name, "DiscordID", "=", event.getAuthor().getId(), bot.getTableName());
|
||||
}else {
|
||||
bot.getSQL().update("INSERT INTO " + bot.getTableName() + " (DiscordID,MinecraftName) VALUES (\'" + event.getAuthor().getId() + "\',\'" + name + "\');");
|
||||
|
||||
if(bot.getPlugin().mainRecordKeeper()) {
|
||||
|
||||
if(bot.getSQL().itemExists("DiscordID", event.getAuthor().getId(), bot.getTableName())) {
|
||||
bot.getSQL().set("MinecraftName", name, "DiscordID", "=", event.getAuthor().getId(), bot.getTableName());
|
||||
}else {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@ public class PlayerListener implements Listener {
|
|||
public void onPlayerLogin(PlayerLoginEvent event){
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.hasPermission("bcraftbot.bypasscheck")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!plugin.isMember(player) && !plugin.isExempt(player.getName())) {
|
||||
event.disallow(Result.KICK_OTHER, plugin.getKickMessage());
|
||||
return;
|
||||
|
@ -32,24 +36,27 @@ public class PlayerListener implements Listener {
|
|||
|
||||
if(plugin.checkRole() && !plugin.isExempt(player.getName())) {
|
||||
boolean allow = false;
|
||||
|
||||
for(Guild guild : plugin.getBot().getJDA().getGuilds()) {
|
||||
|
||||
Role role = null;
|
||||
for(Role r : guild.getRoles()) {
|
||||
if(r.getName().equalsIgnoreCase(plugin.getRequiredRole())) {
|
||||
role = r;
|
||||
for(String rolename : plugin.getRequiredRole().split(",")) {
|
||||
|
||||
Role role = null;
|
||||
for(Role r : guild.getRoles()) {
|
||||
if(r.getName().equalsIgnoreCase(rolename)) {
|
||||
role = r;
|
||||
}
|
||||
}
|
||||
|
||||
User user = plugin.getDiscordUser(player);
|
||||
Member mem = guild.getMember(user);
|
||||
|
||||
if(user != null && user.getMutualGuilds().contains(guild) && role != null) {
|
||||
if(mem.getRoles().contains(role)) {
|
||||
allow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
User user = plugin.getDiscordUser(player);
|
||||
Member mem = guild.getMember(user);
|
||||
|
||||
if(user != null && user.getMutualGuilds().contains(guild) && role != null) {
|
||||
if(mem.getRoles().contains(role)) {
|
||||
allow = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!allow) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
main: com.fpghoti.bcraftbot.Main
|
||||
version: 1.0
|
||||
version: 1.1
|
||||
api-version: 1.13
|
||||
name: BCraftBot
|
||||
descripion: Discord-based whitelisting system for Minecraft
|
||||
|
|
Loading…
Reference in New Issue