fixed issues causing plugin not to operate

This commit is contained in:
Ghoti 2019-02-15 00:42:27 -06:00
parent fbe9ed4cb8
commit 5b9fb5548e
8 changed files with 100 additions and 185 deletions

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>FPMB</groupId>
<artifactId>FPMB</artifactId>
<version>2.2</version>
<groupId>com.fpghoti</groupId>
<artifactId>BCraftBot</artifactId>
<version>1.0</version>
<build>
<resources>
<resource>
@ -38,73 +38,13 @@
</plugins>
</build>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>soluvas-public-thirdparty</id>
<url>http://nexus.bippo.co.id/nexus/content/repositories/soluvas-public-thirdparty/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.0</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20171018</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-websocket-client</artifactId>
<version>2.3</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
@ -133,6 +73,20 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

64
pom.xml
View File

@ -5,22 +5,11 @@
<artifactId>BCraftBot</artifactId>
<version>1.0</version>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>soluvas-public-thirdparty</id>
<url>http://nexus.bippo.co.id/nexus/content/repositories/soluvas-public-thirdparty/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<build>
<resources>
@ -58,43 +47,16 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.5.0_327</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20171018</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
<type>pom</type>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
@ -108,23 +70,5 @@
<version>3.6</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-websocket-client</artifactId>
<version>2.3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -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();
@ -213,10 +213,13 @@ public class Main extends JavaPlugin {
public boolean isMember(Player p) {
String name = p.getName().toLowerCase();
ArrayList<String> ids = new ArrayList<String>();
ResultSet rs = sql.query("SELECT * FROM " + sqltable + " WHERE MinecraftName = " + name.toLowerCase());
ResultSet rs;
if(sql.itemExists("MinecraftName", name, sqltable)) {
rs = sql.query("SELECT * FROM " + sqltable + " HAVING MinecraftName = " + "\'" + name.toLowerCase() + "\';");
try {
while (rs.next()) {
ids.add(rs.getString("DiscordID"));
String tempid = rs.getString("DiscordID");
ids.add(tempid);
}
} catch (SQLException e) {
log(Level.SEVERE, "Error getting Discord IDs from database!");
@ -227,15 +230,19 @@ public class Main extends JavaPlugin {
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();
if(sql.itemExists("UUID", uuid, sqltable)) {
ids = new ArrayList<String>();
rs = sql.query("SELECT * FROM " + sqltable + " WHERE UUID = " + uuid);
rs = sql.query("SELECT * FROM " + sqltable + " WHERE UUID = " + "\'" + uuid + "\';");
try {
while (rs.next()) {
ids.add(rs.getString("DiscordID"));
@ -249,20 +256,20 @@ public class Main extends JavaPlugin {
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 + ";");
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<String> ids = new ArrayList<String>();
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"));

View File

@ -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();
}

View File

@ -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 {

View File

@ -8,7 +8,7 @@ public class CommandParser {
public CommandContainer parse(String rw, MessageReceivedEvent e){
ArrayList<String> split = new ArrayList<String>();
String raw = rw;
String fixed = raw.replaceFirst("-", "");
String fixed = raw.replaceFirst("!", "");
String[] splitf = fixed.split(" ");
for(String s: splitf){
split.add(s);

View File

@ -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!");

View File

@ -24,8 +24,14 @@ 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()) {
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;
@ -44,9 +50,7 @@ public class PlayerListener implements Listener {
}
}
}else {
event.disallow(Result.KICK_OTHER, plugin.getKickMessage());
}
}
}