diff --git a/src/de/steamwar/bungeecore/listeners/CheckListener.java b/src/de/steamwar/bungeecore/listeners/CheckListener.java index 1c10b4b..985ce05 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 914f1ff..f9fa285 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; }