Fixes to my last commit

This commit is contained in:
Dalton 2017-09-29 21:18:14 -04:00
parent f7debb212d
commit 6b98e23a0f
10 changed files with 36 additions and 92 deletions

View File

@ -38,4 +38,4 @@ compileJava.options.encoding = 'UTF-8'
compileJava.options.fork = true compileJava.options.fork = true
// Change this if you are getting errors building // Change this if you are getting errors building
compileJava.options.forkOptions.executable = 'C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\javac.exe' compileJava.options.forkOptions.executable = 'C:\\Program Files\\Java\\jdk1.8.0_131\\bin\\javac.exe'

View File

@ -81,6 +81,7 @@ public class Database {
} }
} catch (SQLException exception) { } catch (SQLException exception) {
System.out.println("INFO: Couldn't send update / query! : " + exception.getLocalizedMessage()); System.out.println("INFO: Couldn't send update / query! : " + exception.getLocalizedMessage());
exception.printStackTrace();
return Optional.empty(); return Optional.empty();
} }
} }
@ -99,6 +100,7 @@ public class Database {
} catch (SQLException e) { } catch (SQLException e) {
// Can't handle closing statement // Can't handle closing statement
System.out.println("INFO: Close connection! : " + e.getLocalizedMessage()); System.out.println("INFO: Close connection! : " + e.getLocalizedMessage());
e.printStackTrace();
} }
} }
@ -149,6 +151,7 @@ public class Database {
return Optional.of(preparedStatement); return Optional.of(preparedStatement);
} catch (SQLException exception) { } catch (SQLException exception) {
System.out.println("INFO: Couldn't prepare statement : " + exception.getLocalizedMessage()); System.out.println("INFO: Couldn't prepare statement : " + exception.getLocalizedMessage());
exception.printStackTrace();
return Optional.empty(); return Optional.empty();
} }
} }
@ -164,7 +167,8 @@ public class Database {
try { try {
return Optional.of(source.getConnection().prepareStatement(sql)); return Optional.of(source.getConnection().prepareStatement(sql));
} catch (SQLException exception) { } catch (SQLException exception) {
System.out.println("INFO: Couldn't send update / query! : " + exception.getLocalizedMessage()); System.out.println("INFO: Couldn't send prepared statement! : " + exception.getLocalizedMessage());
exception.printStackTrace();
return Optional.empty(); return Optional.empty();
} }
} }

View File

@ -111,6 +111,7 @@ public class Rixa {
try { try {
int shards = 5; int shards = 5;
for (int i = 0; i < shards; i++) { for (int i = 0; i < shards; i++) {
Thread.sleep(5000);
Logger.getLogger("Rixa").info("Loading shard #" + i); Logger.getLogger("Rixa").info("Loading shard #" + i);
JDABuilder jda = new JDABuilder(AccountType.BOT) JDABuilder jda = new JDABuilder(AccountType.BOT)
.setToken(config.getJsonObject().getString("secretToken")) .setToken(config.getJsonObject().getString("secretToken"))
@ -160,16 +161,13 @@ public class Rixa {
return Logger.getLogger("Rixa"); return Logger.getLogger("Rixa");
} }
public void exit() {
getShardsList().forEach(JDA::shutdown);
}
public void close() { public void close() {
try { try {
Guilds.getGuilds().values().parallelStream().forEach(RixaGuild::save); Thread.sleep(5000);
Thread.sleep(1200);
database.close(); database.close();
Thread.sleep(200); Thread.sleep(200);
getShardsList().forEach(JDA::shutdown);
Thread.sleep(200);
System.exit(0); System.exit(0);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
getLogger().severe("Could not shutdown Rixa instance."); getLogger().severe("Could not shutdown Rixa instance.");

View File

@ -4,7 +4,10 @@ import me.savvy.rixa.Rixa;
import me.savvy.rixa.commands.handlers.Command; import me.savvy.rixa.commands.handlers.Command;
import me.savvy.rixa.commands.handlers.CommandExec; import me.savvy.rixa.commands.handlers.CommandExec;
import me.savvy.rixa.commands.handlers.CommandType; import me.savvy.rixa.commands.handlers.CommandType;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.guild.management.Guilds;
import me.savvy.rixa.utils.MessageBuilder; import me.savvy.rixa.utils.MessageBuilder;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
@ -22,8 +25,19 @@ public class OwnerCommand implements CommandExec {
.setColor(event.getMember().getColor()).queue(event.getChannel()); .setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;
} }
Rixa.getInstance().close();
Rixa.getInstance().exit();
try {
for (RixaGuild rixaGuild : Guilds.getGuilds().values()) {
Thread.sleep(50);
rixaGuild.save();
}
Thread.sleep(500);
Rixa.getInstance().close();
System.exit(0);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Rixa.getInstance().close();
} }
} }

View File

@ -57,7 +57,11 @@ public class GuildSettings {
Query query = new Query("SELECT * FROM `settings` WHERE `guild_id` = ?"); Query query = new Query("SELECT * FROM `settings` WHERE `guild_id` = ?");
query.setString(guild.getId()); query.setString(guild.getId());
Optional<?> optional = Rixa.getDatabase().send(query); Optional<?> optional = Rixa.getDatabase().send(query);
if (!optional.isPresent() || !(optional.get() instanceof ResultSet)) { if (!optional.isPresent()) {
if (!(optional.get() instanceof ResultSet)) {
Rixa.getInstance().getLogger().severe("Could not find " + guild.getName() + " it wasn't an instance of result set!, GuildSettings:61");
return;
}
Rixa.getInstance().getLogger().severe("Could not find " + guild.getName() + ", GuildSettings:60"); Rixa.getInstance().getLogger().severe("Could not find " + guild.getName() + ", GuildSettings:60");
return; return;
} }

View File

@ -51,7 +51,6 @@ public class UserData {
} }
try { try {
Query query = new Query("SELECT * FROM `levels` WHERE `guild_id` = ? AND `user_id` = ?;"); Query query = new Query("SELECT * FROM `levels` WHERE `guild_id` = ? AND `user_id` = ?;");
query.setString("levels");
query.setString(guild.getId()); query.setString(guild.getId());
query.setString(user.getId()); query.setString(user.getId());
Optional<?> optional = Rixa.getDatabase().send(query); Optional<?> optional = Rixa.getDatabase().send(query);

View File

@ -1,50 +0,0 @@
package me.savvy.rixa.modules.economy;
import lombok.Getter;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.modules.RixaModule;
import me.savvy.rixa.utils.DatabaseUtils;
import java.util.HashMap;
import java.util.Map;
public class Economy implements RixaModule {
public Economy(RixaGuild rixaGuild) {
this.rixaGuild = rixaGuild;
}
@Getter
private RixaGuild rixaGuild;
@Getter
private Map<String, EconomyData> userData = new HashMap<>();
private boolean enabled;
@Override
public String getName() {
return "Economy";
}
@Override
public String getDescription() {
return "Rixa Economy Module";
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public void load() { }
@Override
public void save() {
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
DatabaseUtils.update("modules", "x", "guild_id", enabled, rixaGuild.getGuild().getId());
}
}

View File

@ -1,25 +0,0 @@
package me.savvy.rixa.modules.economy;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.User;
public class EconomyData {
@Getter
@Setter
private int amount;
@Getter
@Setter
private Guild guild;
@Getter
@Setter
private User user;
public EconomyData(User user, Guild guild) {
setUser(user);
setGuild(guild);
}
}

View File

@ -19,10 +19,6 @@ import java.util.Optional;
* Created by Timber on 5/23/2017. * Created by Timber on 5/23/2017.
*/ */
public class MusicModule implements RixaModule { public class MusicModule implements RixaModule {
public MusicModule(RixaGuild rixaGuild) {
this.guild = rixaGuild.getGuild();
}
private Database db; private Database db;
@Getter @Getter
@Setter @Setter
@ -33,6 +29,11 @@ public class MusicModule implements RixaModule {
@Getter @Getter
private Guild guild; private Guild guild;
public MusicModule(RixaGuild rixaGuild) {
this.guild = rixaGuild.getGuild();
load();
}
@Override @Override
public void load() { public void load() {
try { try {

View File

@ -13,7 +13,6 @@ import java.util.Optional;
public class DatabaseUtils { public class DatabaseUtils {
public static Result update(String table, String setting, String key, Object placeholder, Object placeholder2) { public static Result update(String table, String setting, String key, Object placeholder, Object placeholder2) {
Update update = new Update("UPDATE `" + table + "` SET `" + setting + "` = ? WHERE `" + key + "` = ?;"); Update update = new Update("UPDATE `" + table + "` SET `" + setting + "` = ? WHERE `" + key + "` = ?;");
update.setObject(placeholder); update.setObject(placeholder);
update.setObject(placeholder2); update.setObject(placeholder2);