diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index f434a0b..8095fa9 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -1,9 +1,9 @@
4.0.0
- FPMB
- FPMB
- 2.2
+ com.fpghoti
+ BCraftBot
+ 1.0
@@ -38,73 +38,13 @@
-
- bungeecord-repo
- https://oss.sonatype.org/content/repositories/snapshots
-
jcenter
jcenter-bintray
http://jcenter.bintray.com
-
-
- false
-
- soluvas-public-thirdparty
- http://nexus.bippo.co.id/nexus/content/repositories/soluvas-public-thirdparty/
-
-
- net.java.dev.jna
- jna
- 4.5.0
- pom
- compile
-
-
- org.json
- json
- 20171018
- pom
- compile
-
-
- net.sf.trove4j
- trove4j
- 3.0.3
- pom
- compile
-
-
- org.apache.commons
- commons-collections4
- 4.1
- pom
- compile
-
-
- org.apache.commons
- commons-lang3
- 3.6
- pom
- compile
-
-
- com.squareup.okhttp
- okhttp
- 2.7.5
- pom
- compile
-
-
- com.neovisionaries
- nv-websocket-client
- 2.3
- pom
- compile
-
org.bukkit
bukkit
@@ -133,6 +73,20 @@
+
+ org.apache.commons
+ commons-collections4
+ 4.1
+ pom
+ compile
+
+
+ org.apache.commons
+ commons-lang3
+ 3.6
+ pom
+ compile
+
diff --git a/pom.xml b/pom.xml
index a27565c..a80af22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,22 +5,11 @@
BCraftBot
1.0
-
- bungeecord-repo
- https://oss.sonatype.org/content/repositories/snapshots
-
jcenter
jcenter-bintray
http://jcenter.bintray.com
-
- soluvas-public-thirdparty
- http://nexus.bippo.co.id/nexus/content/repositories/soluvas-public-thirdparty/
-
- false
-
-
@@ -58,43 +47,16 @@
-
- ch.qos.logback
- logback-core
- 1.2.3
-
-
- ch.qos.logback
- logback-classic
- 1.2.3
-
-
- joda-time
- joda-time
- 2.3
-
net.dv8tion
JDA
3.5.0_327
- net.java.dev.jna
- jna
- 4.5.0
- pom
-
-
- org.json
- json
- 20171018
- pom
-
-
- net.sf.trove4j
- trove4j
- 3.0.3
- pom
+ org.bukkit
+ bukkit
+ 1.13.2-R0.1-SNAPSHOT
+ provided
org.apache.commons
@@ -108,23 +70,5 @@
3.6
pom
-
- com.squareup.okhttp
- okhttp
- 2.7.5
- pom
-
-
- com.neovisionaries
- nv-websocket-client
- 2.3
- pom
-
-
- org.bukkit
- bukkit
- 1.13.2-R0.1-SNAPSHOT
- provided
-
\ No newline at end of file
diff --git a/src/main/java/com/fpghoti/bcraftbot/Main.java b/src/main/java/com/fpghoti/bcraftbot/Main.java
index 6c072db..5fc040a 100644
--- a/src/main/java/com/fpghoti/bcraftbot/Main.java
+++ b/src/main/java/com/fpghoti/bcraftbot/Main.java
@@ -52,7 +52,7 @@ public class Main extends JavaPlugin {
sql.connect();
if(!sql.tableExists(sqltable)){
log(Level.INFO, "Table not found. Creating new table...");
- sql.update("CREATE TABLE " + sqltable + " (DiscordID NOT NULL CHAR(18), MinecraftName VARCHAR(16), UUID CHAR(36), PRIMARY KEY (DiscordID);");
+ sql.update("CREATE TABLE " + sqltable + " (DiscordID CHAR(18), MinecraftName VARCHAR(16), UUID CHAR(36), PRIMARY KEY (DiscordID));");
log(Level.INFO, "Table created!");
}
startReconnect();
@@ -180,7 +180,7 @@ public class Main extends JavaPlugin {
public ServerBot getBot() {
return bot;
}
-
+
public boolean isExempt(String name) {
for(String item: exempt) {
if(item.equalsIgnoreCase(name)) {
@@ -189,15 +189,15 @@ public class Main extends JavaPlugin {
}
return false;
}
-
+
public boolean assignRole() {
return assignrole;
}
-
+
public String getAssignRoleName() {
return rolename;
}
-
+
public String getKickMessage() {
return kickmsg;
}
@@ -213,56 +213,63 @@ public class Main extends JavaPlugin {
public boolean isMember(Player p) {
String name = p.getName().toLowerCase();
ArrayList ids = new ArrayList();
- ResultSet rs = sql.query("SELECT * FROM " + sqltable + " WHERE MinecraftName = " + name.toLowerCase());
- try {
- while (rs.next()) {
- ids.add(rs.getString("DiscordID"));
+ ResultSet rs;
+ if(sql.itemExists("MinecraftName", name, sqltable)) {
+ rs = sql.query("SELECT * FROM " + sqltable + " HAVING MinecraftName = " + "\'" + name.toLowerCase() + "\';");
+ try {
+ while (rs.next()) {
+ String tempid = rs.getString("DiscordID");
+ ids.add(tempid);
+ }
+ } catch (SQLException e) {
+ log(Level.SEVERE, "Error getting Discord IDs from database!");
+ e.printStackTrace();
}
- } catch (SQLException e) {
- log(Level.SEVERE, "Error getting Discord IDs from database!");
- e.printStackTrace();
- }
- for(String id : ids) {
- User user = bot.getJDA().getUserById(id);
- if(user != null) {
- for(Guild guild : bot.getJDA().getGuilds()) {
- if(guild.isMember(user)) {
- return true;
+ for(String id : ids) {
+ User user = bot.getJDA().getUserById(id);
+ if(user != null) {
+ for(Guild guild : bot.getJDA().getGuilds()) {
+ if(guild.isMember(user)) {
+ String uuid = p.getUniqueId().toString();
+ sql.update("UPDATE " + sqltable + " SET UUID = " + "\'" + uuid + "\'" + " WHERE DiscordID = " + "\'" + id + "\';");
+ return true;
+ }
}
}
}
}
String uuid = p.getUniqueId().toString();
- ids = new ArrayList();
- rs = sql.query("SELECT * FROM " + sqltable + " WHERE UUID = " + uuid);
- try {
- while (rs.next()) {
- ids.add(rs.getString("DiscordID"));
+ if(sql.itemExists("UUID", uuid, sqltable)) {
+ ids = new ArrayList();
+ rs = sql.query("SELECT * FROM " + sqltable + " WHERE UUID = " + "\'" + uuid + "\';");
+ try {
+ while (rs.next()) {
+ ids.add(rs.getString("DiscordID"));
+ }
+ } catch (SQLException e) {
+ log(Level.SEVERE, "Error getting Discord IDs from database!");
+ e.printStackTrace();
}
- } catch (SQLException e) {
- log(Level.SEVERE, "Error getting Discord IDs from database!");
- e.printStackTrace();
- }
- for(String id : ids) {
- User user = bot.getJDA().getUserById(id);
- if(user != null) {
- for(Guild guild : bot.getJDA().getGuilds()) {
- if(guild.isMember(user)) {
- sql.update("UPDATE " + sqltable + " SET MinecraftName = " + p.getName().toLowerCase() + " WHERE DiscordID = " + id + ";");
- return true;
+ for(String id : ids) {
+ User user = bot.getJDA().getUserById(id);
+ if(user != null) {
+ for(Guild guild : bot.getJDA().getGuilds()) {
+ if(guild.isMember(user)) {
+ sql.update("UPDATE " + sqltable + " SET MinecraftName = " + "\'" + p.getName().toLowerCase() + "\'" + " WHERE DiscordID = " + "\'" + id + "\';");
+ return true;
+ }
}
}
}
}
-
return false;
}
-
+
public User getDiscordUser(Player p) {
String name = p.getName().toLowerCase();
ArrayList ids = new ArrayList();
- ResultSet rs = sql.query("SELECT * FROM " + sqltable + " WHERE MinecraftName = " + name.toLowerCase());
+ ResultSet rs = sql.query("SELECT * FROM " + sqltable + " HAVING MinecraftName = " + "\'" + name.toLowerCase() + "\';");
try {
while (rs.next()) {
ids.add(rs.getString("DiscordID"));
@@ -283,5 +290,5 @@ public class Main extends JavaPlugin {
}
return null;
}
-
+
}
\ No newline at end of file
diff --git a/src/main/java/com/fpghoti/bcraftbot/bot/ServerBot.java b/src/main/java/com/fpghoti/bcraftbot/bot/ServerBot.java
index 3846263..db770aa 100644
--- a/src/main/java/com/fpghoti/bcraftbot/bot/ServerBot.java
+++ b/src/main/java/com/fpghoti/bcraftbot/bot/ServerBot.java
@@ -38,6 +38,7 @@ public class ServerBot {
jda.addEventListener(new BotListener(this));
jda.setAutoReconnect(true);
String link = "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId();
+ link = link + "&scope=bot&permissions=8";
plugin.log(Level.INFO, "Connection successful!");
plugin.log(Level.INFO, "You can add this bot to Discord using this link: ");
plugin.log(Level.INFO, link);
@@ -82,7 +83,6 @@ public class ServerBot {
return jda;
}
-
public void shutDown(){
jda.shutdown();
}
diff --git a/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java b/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java
index 032f341..ed101bf 100644
--- a/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java
+++ b/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java
@@ -27,7 +27,10 @@ public class AddMeCommand implements Command{
public void action(String[] args, MessageReceivedEvent event) {
if(args.length == 1) {
String name = args[0].toLowerCase();
- bot.log(Level.INFO, event.getAuthor().getName() + " issued a Discord Bot command: -addme " + name);
+ if(name.length() > 16) {
+ 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 {
diff --git a/src/main/java/com/fpghoti/bcraftbot/bot/util/CommandParser.java b/src/main/java/com/fpghoti/bcraftbot/bot/util/CommandParser.java
index ea84251..a3e7266 100644
--- a/src/main/java/com/fpghoti/bcraftbot/bot/util/CommandParser.java
+++ b/src/main/java/com/fpghoti/bcraftbot/bot/util/CommandParser.java
@@ -8,7 +8,7 @@ public class CommandParser {
public CommandContainer parse(String rw, MessageReceivedEvent e){
ArrayList split = new ArrayList();
String raw = rw;
- String fixed = raw.replaceFirst("-", "");
+ String fixed = raw.replaceFirst("!", "");
String[] splitf = fixed.split(" ");
for(String s: splitf){
split.add(s);
diff --git a/src/main/java/com/fpghoti/bcraftbot/command/AddExempt.java b/src/main/java/com/fpghoti/bcraftbot/command/AddExempt.java
index 6316374..8e84609 100644
--- a/src/main/java/com/fpghoti/bcraftbot/command/AddExempt.java
+++ b/src/main/java/com/fpghoti/bcraftbot/command/AddExempt.java
@@ -38,6 +38,9 @@ public class AddExempt implements CommandExecutor{
}
}
String name = args[0];
+ if(name.length() > 16) {
+ return true;
+ }
plugin.addExempt(name);
if(sender instanceof Player) {
((Player)sender).sendMessage(ChatColor.GREEN + "[BCraftBot] Player added to the exempt list!");
diff --git a/src/main/java/com/fpghoti/bcraftbot/listener/PlayerListener.java b/src/main/java/com/fpghoti/bcraftbot/listener/PlayerListener.java
index 4d46c82..9edea9f 100644
--- a/src/main/java/com/fpghoti/bcraftbot/listener/PlayerListener.java
+++ b/src/main/java/com/fpghoti/bcraftbot/listener/PlayerListener.java
@@ -24,29 +24,33 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerLogin(PlayerLoginEvent event){
Player player = event.getPlayer();
- if(plugin.isMember(player) || plugin.isExempt(player.getName())) {
- if(plugin.assignRole()) {
- for(Guild guild : plugin.getBot().getJDA().getGuilds()) {
- Role role = null;
- for(Role r : guild.getRoles()) {
- if(r.getName().equalsIgnoreCase(plugin.getAssignRoleName())) {
- role = r;
- }
- }
-
- User user = plugin.getDiscordUser(player);
- Member mem = guild.getMember(user);
-
- if(user != null && user.getMutualGuilds().contains(guild) && role != null) {
- guild.getController().addRolesToMember(mem, role).queue();
- }
-
- }
- }
- }else {
+ if(!plugin.isMember(player) && !plugin.isExempt(player.getName())) {
event.disallow(Result.KICK_OTHER, plugin.getKickMessage());
+ return;
+ }
+ if(plugin.assignRole() && !plugin.isExempt(player.getName())) {
+
+
+ for(Guild guild : plugin.getBot().getJDA().getGuilds()) {
+
+ Role role = null;
+ for(Role r : guild.getRoles()) {
+ if(r.getName().equalsIgnoreCase(plugin.getAssignRoleName())) {
+ role = r;
+ }
+ }
+
+ User user = plugin.getDiscordUser(player);
+ Member mem = guild.getMember(user);
+
+ if(user != null && user.getMutualGuilds().contains(guild) && role != null) {
+ guild.getController().addRolesToMember(mem, role).queue();
+ }
+
+ }
}
}
+
}