Skip to content

Commit 1137d9c

Browse files
committed
Add more error checking and squash some bugs
1 parent 3b6e018 commit 1137d9c

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

src/main/java/com/funniray/lbwd/Datastores/H2Store.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class H2Store implements Datastore {
3838
public static final String GET_BANS_BY_UUID_HISTORICAL = "SELECT *, false as warned FROM bans WHERE UUID=?";//language=H2
3939
public static final String GET_MUTES_BY_UUID_HISTORICAL = "SELECT *, false as warned FROM mutes WHERE UUID=?";//language=H2
4040
public static final String GET_WARNS_BY_UUID_HISTORICAL = "SELECT * FROM warnings WHERE UUID=?";//language=H2
41-
public static final String GET_KICKS_BY_UUID_HISTORICAL = "SELECT *, false as warned, \"00000000-0000-0000-0000-000000000000\" as removed_by_uuid, null as removed_by_name, null as removed_by_date FROM kicks WHERE UUID=?"; //language=H2
41+
public static final String GET_KICKS_BY_UUID_HISTORICAL = "SELECT *, false as warned, '00000000-0000-0000-0000-000000000000' as removed_by_uuid, null as removed_by_name, null as removed_by_date FROM kicks WHERE UUID=?"; //language=H2
4242

4343

4444
public static final String GET_BANS_BY_UUID_ACTIVE = "SELECT *, false AS warned FROM bans WHERE uuid=? AND ipban=false AND active=true AND (until>=(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)*1000) OR until=-1)"; //language=H2
@@ -139,6 +139,7 @@ public HashSet<Ban> getHistoricalKicks(UUID uuid) {
139139

140140
@Override
141141
public HashSet<Ban> getActiveBans(String uuid, String node, boolean ip) {
142+
node = node.equals("warn") ? "warning" : node;
142143
if (ip) {
143144
return runBanStatement(GET_SOMETHING_BY_IP_ACTIVE.replace("%node%",node), uuid);
144145
}
@@ -161,9 +162,9 @@ public HashSet<Ban> getActiveMutes(UUID uuid) {
161162
@Override
162163
public HashSet<Ban> getActiveWarns(String uuid) {
163164
if (uuid.contains(".") || uuid.contains(":")) {
164-
return runBanStatement(GET_SOMETHING_BY_IP_ACTIVE.replace("%node%","warn"), uuid);
165+
return runBanStatement(GET_SOMETHING_BY_IP_ACTIVE.replace("%node%","warning"), uuid);
165166
}
166-
return runBanStatement(GET_SOMETHING_BY_UUID_ACTIVE.replace("%node%","warn"), uuid);
167+
return runBanStatement(GET_SOMETHING_BY_UUID_ACTIVE.replace("%node%","warning"), uuid);
167168
}
168169

169170

src/main/java/com/funniray/lbwd/Datastores/SQLStore.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class SQLStore implements Datastore {
4141
public static final String GET_BANS_BY_UUID_HISTORICAL = "SELECT *, false as warned FROM "+table_prefix+"bans WHERE UUID=?;";
4242
public static final String GET_MUTES_BY_UUID_HISTORICAL = "SELECT *, false as warned FROM "+table_prefix+"mutes WHERE UUID=?;";
4343
public static final String GET_WARNS_BY_UUID_HISTORICAL = "SELECT * FROM "+table_prefix+"warnings WHERE UUID=?;";
44-
public static final String GET_KICKS_BY_UUID_HISTORICAL = "SELECT *, false as warned, \"00000000-0000-0000-0000-000000000000\" as removed_by_uuid, null as removed_by_name, null as removed_by_date FROM "+table_prefix+"kicks WHERE UUID=?;";
44+
public static final String GET_KICKS_BY_UUID_HISTORICAL = "SELECT *, false as warned, '00000000-0000-0000-0000-000000000000' as removed_by_uuid, null as removed_by_name, null as removed_by_date FROM kicks WHERE UUID=?";
4545

4646
public static final String GET_BANS_BY_UUID_ACTIVE = "SELECT *, false AS warned FROM "+table_prefix+"bans WHERE uuid=? AND ipban=false AND active=true AND (until>=(UNIX_TIMESTAMP()*1000) OR until=-1);";
4747
public static final String GET_SOMETHING_BY_UUID_ACTIVE = "SELECT *, false AS warned FROM "+table_prefix+"%node%s WHERE uuid=? AND ipban=false AND active=true AND (until>=(UNIX_TIMESTAMP()*1000) OR until=-1);";
@@ -142,6 +142,7 @@ public HashSet<Ban> getHistoricalKicks(UUID uuid) {
142142

143143
@Override
144144
public HashSet<Ban> getActiveBans(String uuid, String node, boolean ip) {
145+
node = node.equals("warn") ? "warning" : node;
145146
if (ip) {
146147
return runBanStatement(GET_SOMETHING_BY_IP_ACTIVE.replace("%node%",node), uuid);
147148
}
@@ -164,9 +165,9 @@ public HashSet<Ban> getActiveMutes(UUID uuid) {
164165
@Override
165166
public HashSet<Ban> getActiveWarns(String uuid) {
166167
if (uuid.contains(".") || uuid.contains(":")) {
167-
return runBanStatement(GET_SOMETHING_BY_IP_ACTIVE.replace("%node%","warn"), uuid);
168+
return runBanStatement(GET_SOMETHING_BY_IP_ACTIVE.replace("%node%","warning"), uuid);
168169
}
169-
return runBanStatement(GET_SOMETHING_BY_UUID_ACTIVE.replace("%node%","warn"), uuid);
170+
return runBanStatement(GET_SOMETHING_BY_UUID_ACTIVE.replace("%node%","warning"), uuid);
170171
}
171172

172173

src/main/java/com/funniray/lbwd/commands/BanCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public boolean onExecute(CommandSender commandSender, String s, String[] strings
5252
return true;
5353
}
5454

55+
if (ban == null) {
56+
return true;
57+
}
58+
5559
LBWD.datastore.addBan(ban);
5660

5761
String message = String.format((ban.isSilent()?LBWD.getConfigString("SilentPrefix"):"")+LBWD.getConfigString("BanBroadcast"),ban.getName(),ban.getBannedByName(),ban.getReason(),ban.getUntilString());

src/main/java/com/funniray/lbwd/commands/HistoryCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,28 @@ public boolean onExecute(CommandSender commandSender, String s, String[] strings
6565
Set<Ban> kicks = LBWD.datastore.getHistoricalKicks(uuid);
6666

6767

68-
if (bans.size() > 0) {
68+
if (bans != null && bans.size() > 0) {
6969
commandSender.sendMessage(Colors.DARK_RED + strings[0] + "'s bans:");
7070
for(Ban ban : bans) {
7171
commandSender.sendMessage(Colors.GREEN + "Banned at "+Colors.AQUA+(new Date((long) ban.getTime())).toString() + Colors.GREEN + (ban.getUntil()>0?" for "+ Colors.DARK_AQUA + DateUtils.getDurationBreakdown((long) ((long) ban.getUntil()-ban.getTime())) +Colors.GREEN:"")+ " by "+Colors.BLUE+ban.getBannedByName() +Colors.GREEN+ " for "+Colors.LIGHT_PURPLE+ban.getReason()+Colors.GREEN + (ban.isActive()?"":" removed by "+Colors.GRAY+ban.getRemovedByName()));
7272
}
7373
}
7474

75-
if (mutes.size() > 0) {
75+
if (mutes != null && mutes.size() > 0) {
7676
commandSender.sendMessage(Colors.DARK_RED + strings[0] + "'s mutes:");
7777
for(Ban ban : mutes) {
7878
commandSender.sendMessage(Colors.GREEN + "Muted at "+Colors.AQUA+(new Date((long) ban.getTime())).toString() + Colors.GREEN + (ban.getUntil()>0?" for "+ Colors.DARK_AQUA + DateUtils.getDurationBreakdown((long) ((long) ban.getUntil()-ban.getTime())) +Colors.GREEN:"")+ " by "+Colors.BLUE+ban.getBannedByName() +Colors.GREEN+ " for "+Colors.LIGHT_PURPLE+ban.getReason()+Colors.GREEN + (ban.isActive()?"":" removed by "+Colors.GRAY+ban.getRemovedByName()));
7979
}
8080
}
8181

82-
if (warns.size() > 0) {
82+
if (warns != null && warns.size() > 0) {
8383
commandSender.sendMessage(Colors.DARK_RED + strings[0] + "'s warns:");
8484
for(Ban ban : warns) {
8585
commandSender.sendMessage(Colors.GREEN + "Warned at "+Colors.AQUA+(new Date((long) ban.getTime())).toString() + Colors.GREEN + (ban.getUntil()>0?" for "+ Colors.DARK_AQUA + DateUtils.getDurationBreakdown((long) ((long) ban.getUntil()-ban.getTime())) +Colors.GREEN:"")+ " by "+Colors.BLUE+ban.getBannedByName() +Colors.GREEN+ " for "+Colors.LIGHT_PURPLE+ban.getReason()+Colors.GREEN + (ban.isActive()?"":" removed by "+Colors.GRAY+ban.getRemovedByName()));
8686
}
8787
}
8888

89-
if (kicks.size() > 0) {
89+
if (kicks != null && kicks.size() > 0) {
9090
commandSender.sendMessage(Colors.DARK_RED + strings[0] + "'s kicks:");
9191
for(Ban ban : kicks) {
9292
commandSender.sendMessage(Colors.GREEN + "Kicked at "+Colors.AQUA+(new Date((long) ban.getTime())).toString() + Colors.GREEN + (ban.getUntil()>0?" for "+ Colors.DARK_AQUA + DateUtils.getDurationBreakdown((long) ((long) ban.getUntil()-ban.getTime())) +Colors.GREEN:"")+ " by "+Colors.BLUE+ban.getBannedByName() +Colors.GREEN+ " for "+Colors.LIGHT_PURPLE+ban.getReason()+Colors.GREEN + (ban.isActive()?"":" removed by "+Colors.GRAY+ban.getRemovedByName()));

src/main/java/com/funniray/lbwd/commands/MuteCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public boolean onExecute(CommandSender commandSender, String s, String[] strings
5252
return true;
5353
}
5454

55+
if (ban == null) {
56+
return true;
57+
}
58+
5559
LBWD.datastore.addMute(ban);
5660

5761
String message = String.format((ban.isSilent()?LBWD.getConfigString("SilentPrefix"):"")+LBWD.getConfigString("MuteBroadcast"),ban.getName(),ban.getBannedByName(),ban.getReason(),ban.getUntilString());

src/main/java/com/funniray/lbwd/utils/DateUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class DateUtils {
4343
//Credit: Banmanager
4444
public static String getDurationBreakdown(long time) {
4545
if (time <= 0) {
46-
return "99 Years";
46+
return "Indefinite";
4747
}
4848

4949
StringBuilder diff = new StringBuilder();

0 commit comments

Comments
 (0)