From de0bd02d18d4416bb328add5c64b32caa8a6115d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 1 May 2020 12:32:13 +0200 Subject: [PATCH] Implementing check listings Signed-off-by: Lixfel --- .../bungeecore/listeners/CheckListener.java | 23 +++++++++++++++++++ src/de/steamwar/bungeecore/sql/Schematic.java | 15 +++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/CheckListener.java b/src/de/steamwar/bungeecore/listeners/CheckListener.java index 1c10b4b6..985ce05a 100644 --- a/src/de/steamwar/bungeecore/listeners/CheckListener.java +++ b/src/de/steamwar/bungeecore/listeners/CheckListener.java @@ -1,13 +1,36 @@ package de.steamwar.bungeecore.listeners; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.commands.CheckCommand; +import de.steamwar.bungeecore.sql.Schematic; +import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; +import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.event.EventHandler; +import java.util.LinkedList; +import java.util.List; + public class CheckListener extends BasicListener { + @EventHandler + public void onPlayerJoin(PostLoginEvent e){ + ProxiedPlayer player = e.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + + List uncheckedSchematics = new LinkedList<>(); + for(SchematicType type : SchematicType.values()){ + if(type.check()) + uncheckedSchematics.addAll(Schematic.getSchemsOfType(user.getId(), type)); + } + + if(!uncheckedSchematics.isEmpty()) + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast noch §e" + uncheckedSchematics.size() + " §7ungeprüfte Schematic§8(§7s§8)!"); + } + @EventHandler public void onServerSwitch(ServerSwitchEvent e){ ProxiedPlayer player = e.getPlayer(); diff --git a/src/de/steamwar/bungeecore/sql/Schematic.java b/src/de/steamwar/bungeecore/sql/Schematic.java index 914f1ff6..f9fa2858 100644 --- a/src/de/steamwar/bungeecore/sql/Schematic.java +++ b/src/de/steamwar/bungeecore/sql/Schematic.java @@ -48,7 +48,7 @@ public class Schematic { public static List getAllSchemsOfType(SchematicType schemType){ try{ - ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemType = ?", schemType.toDB()); + ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType FROM Schematic WHERE SchemType = ?", schemType.toDB()); List schematics = new ArrayList<>(); while(schematic.next()){ schematics.add(new Schematic(schematic)); @@ -59,6 +59,19 @@ public class Schematic { } } + public static List getSchemsOfType(int userId, SchematicType schemType){ + try{ + ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType FROM Schematic WHERE SchemType = ? AND SchemOwner = ?", schemType.toDB(), userId); + List schematics = new ArrayList<>(); + while(schematic.next()){ + schematics.add(new Schematic(schematic)); + } + return schematics; + }catch(SQLException e){ + throw new SecurityException("Failed loading schems of type", e); + } + } + public int getSchemID() { return schemID; }