From 26f42be2d38fd7dabff09a7ecfff8eef570623e6 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 27 Nov 2017 11:31:23 +0200 Subject: [PATCH] BanData interface to LiteBansData --- .../plan/litebans/LiteBansData.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java index 29bacb72d..e60b23081 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java @@ -11,16 +11,15 @@ import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.html.Html; import java.sql.SQLException; -import java.util.Collection; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; /** * PluginData for LiteBans plugin. * * @author Rsl1122 */ -public class LiteBansData extends PluginData { +public class LiteBansData extends PluginData implements BanData { private final LiteBansDatabaseQueries db; @@ -91,4 +90,30 @@ public class LiteBansData extends PluginData { return analysisContainer; } + + @Override + public boolean isBanned(UUID uuid) { + try { + return !db.getBans(uuid).isEmpty(); + } catch (SQLException e) { + Log.toLog(this.getClass().getName(), e); + } + return false; + } + + @Override + public Collection filterBanned(Collection collection) { + try { + List bans = db.getBans(); + Set banned = new HashSet<>(); + for (BanObject ban : bans) { + banned.add(ban.getUuid()); + } + + return collection.stream().filter(banned::contains).collect(Collectors.toSet()); + } catch (SQLException e) { + Log.toLog(this.getClass().getName(), e); + } + return new HashSet<>(); + } } \ No newline at end of file