Skip to content

Commit

Permalink
* Fixed ClassCastException.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Aug 9, 2022
1 parent 66e8e78 commit 1977daa
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/main/java/de/presti/ree6/sql/SQLWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,12 @@ public boolean isVoiceLevelRewardSetup(String guildId, String roleId, int level)
*/
public List<InviteContainer> getInvites(String guildId) {
ArrayList<InviteContainer> invites = new ArrayList<>();
getEntity(Invite.class, "SELECT * FROM Invites WHERE GID=?", guildId).getEntities().stream().map(o -> {

SQLResponse sqlResponse = getEntity(Invite.class, "SELECT * FROM Invites WHERE GID=?", guildId);

if (!sqlResponse.isSuccess()) return invites;

sqlResponse.getEntities().stream().map(o -> {
Invite invite = (Invite) o;
return new InviteContainer(invite.getUserId(), invite.getGuild(), invite.getCode(), invite.getUses(), false);
}).forEach(invites::add);
Expand Down Expand Up @@ -1312,7 +1317,8 @@ public void setInvite(String guildId, String inviteCreator, String inviteCode, l
* @return {@link Invite} as result if true, then it's saved in our Database | may be null.
*/
public Invite getInvite(String guildId, String inviteCode) {
return (Invite) getEntity(Invite.class, "SELECT * FROM Invites WHERE GID=? AND CODE=?", guildId, inviteCode).getEntity();
SQLResponse sqlResponse = getEntity(Invite.class, "SELECT * FROM Invites WHERE GID=? AND CODE=?", guildId, inviteCode);
return sqlResponse.isSuccess() ? (Invite) sqlResponse.getEntity() : null;
}

/**
Expand All @@ -1324,7 +1330,8 @@ public Invite getInvite(String guildId, String inviteCode) {
* @return {@link Invite} as result if true, then it's saved in our Database | may be null.
*/
public Invite getInvite(String guildId, String inviteCreator, String inviteCode) {
return (Invite) getEntity(Invite.class, "SELECT * FROM Invites WHERE GID=? AND UID=? AND CODE=?", guildId, inviteCreator, inviteCode).getEntity();
SQLResponse sqlResponse = getEntity(Invite.class, "SELECT * FROM Invites WHERE GID=? AND UID=? AND CODE=?", guildId, inviteCreator, inviteCode);
return sqlResponse.isSuccess() ? (Invite) sqlResponse.getEntity() : null;
}

/**
Expand Down Expand Up @@ -1371,7 +1378,8 @@ public void clearInvites(String guildId) {
* @return the Message as {@link String}
*/
public String getMessage(String guildId) {
return ((Setting) getEntity(Setting.class, "SELECT * FROM Settings WHERE GID=? AND NAME=?", guildId, "message_join").getEntity()).getStringValue();
SQLResponse sqlResponse = getEntity(Setting.class, "SELECT * FROM Settings WHERE GID=? AND NAME=?", guildId, "message_join");
return sqlResponse.isSuccess() ? ((Setting) sqlResponse.getEntity()).getStringValue() : "Welcome %user_mention%!\nWe wish you a great stay on %guild_name%";
}

/**
Expand Down Expand Up @@ -1504,7 +1512,13 @@ public List<Setting> getAllSettings(String guildId) {

ArrayList<Setting> settings = new ArrayList<>();

getEntity(Setting.class, "SELECT * FROM Settings WHERE GID = ?", guildId).getEntities().stream().map(Setting.class::cast).forEach(settings::add);
SQLResponse sqlResponse = getEntity(Setting.class, "SELECT * FROM Settings WHERE GID = ?", guildId);

if (!sqlResponse.isSuccess()) {
return settings;
}

sqlResponse.getEntities().stream().map(Setting.class::cast).forEach(settings::add);

// If there is no setting to be found, create every setting.
if (settings.isEmpty()) {
Expand Down

0 comments on commit 1977daa

Please sign in to comment.