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>
|
<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>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -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>
|
||||||
|
|
|
@ -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>();
|
||||||
|
|
|
@ -87,4 +87,8 @@ public class ServerBot {
|
||||||
jda.shutdownNow();
|
jda.shutdownNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Main getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,20 @@ 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.getSQL().itemExists("DiscordID", event.getAuthor().getId(), bot.getTableName())) {
|
|
||||||
bot.getSQL().set("MinecraftName", name, "DiscordID", "=", event.getAuthor().getId(), bot.getTableName());
|
if(bot.getPlugin().mainRecordKeeper()) {
|
||||||
}else {
|
|
||||||
bot.getSQL().update("INSERT INTO " + bot.getTableName() + " (DiscordID,MinecraftName) VALUES (\'" + event.getAuthor().getId() + "\',\'" + 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().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,40 +25,47 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()) {
|
||||||
|
|
||||||
Role role = null;
|
for(String rolename : plugin.getRequiredRole().split(",")) {
|
||||||
for(Role r : guild.getRoles()) {
|
|
||||||
if(r.getName().equalsIgnoreCase(plugin.getRequiredRole())) {
|
Role role = null;
|
||||||
role = r;
|
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) {
|
if(!allow) {
|
||||||
event.disallow(Result.KICK_OTHER, plugin.getKickMessage());
|
event.disallow(Result.KICK_OTHER, plugin.getKickMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(plugin.assignRole() && !plugin.isExempt(player.getName())) {
|
if(plugin.assignRole() && !plugin.isExempt(player.getName())) {
|
||||||
for(Guild guild : plugin.getBot().getJDA().getGuilds()) {
|
for(Guild guild : plugin.getBot().getJDA().getGuilds()) {
|
||||||
|
|
||||||
|
@ -80,5 +87,5 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue