diff --git a/.gitignore b/.gitignore index 723ef36..ec376bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +target \ No newline at end of file diff --git a/src/de/warking/schematicsystem/SchematicSystem.java b/src/de/warking/schematicsystem/SchematicSystem.java index fec5bf4..715d960 100644 --- a/src/de/warking/schematicsystem/SchematicSystem.java +++ b/src/de/warking/schematicsystem/SchematicSystem.java @@ -15,8 +15,8 @@ import org.bukkit.plugin.java.JavaPlugin; public class SchematicSystem extends JavaPlugin { - public static String SCHEM_DIR = "/home/netuser/schematics/"; - public static String PREFIX = "§8[§3Schematic§8] §7"; + public static final String SCHEM_DIR = "/home/netuser/schematics/"; + public static final String PREFIX = "§6Schematic§8» §7"; private static SchematicSystem instance; diff --git a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java index 3ae693f..7bf1738 100644 --- a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java +++ b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java @@ -33,9 +33,9 @@ public class PlayerJoinListener implements Listener { } for(int i = 0; i < files.length; i++) { - if(!schematicNames.contains(files[i].getName().substring(0, files[i].getName().lastIndexOf(".")))) { + if(!schematicNames.contains(files[i].getName().substring(0, files[i].getName().lastIndexOf('.')))) { String fileName = files[i].getName(); - Schematic schematic = new Schematic(fileName.substring(0, fileName.lastIndexOf(".")), player.getUniqueId(), "", SchematicType.normal); + new Schematic(fileName.substring(0, fileName.lastIndexOf('.')), player.getUniqueId(), "", SchematicType.normal); } } diff --git a/src/de/warking/schematicsystem/utils/CheckedSchematic.java b/src/de/warking/schematicsystem/utils/CheckedSchematic.java new file mode 100644 index 0000000..e5a6d61 --- /dev/null +++ b/src/de/warking/schematicsystem/utils/CheckedSchematic.java @@ -0,0 +1,99 @@ +package de.warking.schematicsystem.utils; + +import de.warking.hunjy.MySQL.MySQL; +import de.warking.hunjy.MySQL.WarkingUser; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import static de.warking.hunjy.Core.sql; + +public class CheckedSchematic { + + private final String SchemName; + private final int SchemOwner; + private final int Validator; + private final Timestamp StartTime; + private final Timestamp EndTime; + private final String DeclineReason; + + private CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason, boolean insertDB){ + SchemName = MySQL.disarmString(schemName); + SchemOwner = schemOwner; + Validator = validator; + StartTime = startTime; + EndTime = endTime; + DeclineReason = MySQL.disarmString(declineReason); + if(insertDB) + insertDB(); + } + + public CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason){ + this(schemName, schemOwner, validator, startTime, endTime, declineReason, true); + } + + public CheckedSchematic(String schemName, int schemOwner, UUID validator, Timestamp startTime, Timestamp endTime, String declineReason){ + this(schemName, schemOwner, WarkingUser.get(validator).getId(), startTime, endTime, declineReason, true); + } + + public CheckedSchematic(String schemName, UUID schemOwner, UUID validator, Timestamp startTime, Timestamp endTime, String declineReason){ + this(schemName, WarkingUser.get(schemOwner).getId(), WarkingUser.get(validator).getId(), startTime, endTime, declineReason, true); + } + + private void insertDB(){ + sql.update("INSERT INTO CheckedSchematic" + + " (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason)" + + " VALUES" + + " ('"+ SchemName + "', '" + SchemOwner + "', '" + Validator + "', '" + StartTime.toString() + "', '" + EndTime.toString() + "', '" + DeclineReason + "')"); + } + + public static List getLastDeclined(UUID schemOwner){ + return getLastDelined(WarkingUser.get(schemOwner).getId()); + } + + public static List getLastDelined(int schemOwner){ + List lastDeclined = new ArrayList<>(); + try{ + ResultSet lastRS = sql.select("SELECT * FROM CheckedSchematic WHERE SchemOwner = '" + schemOwner + "' AND DeclineReason != '' ORDER BY EndTime DESC"); + while(lastRS.next()){ + String schemName = lastRS.getString("SchemName"); + int validator = lastRS.getInt("Validator"); + Timestamp startTime = lastRS.getTimestamp("StartTime"); + Timestamp endTime = lastRS.getTimestamp("EndTime"); + String declineReason = lastRS.getString("DeclineReason"); + lastDeclined.add(new CheckedSchematic(schemName, schemOwner, validator, startTime, endTime, declineReason, false)); + } + }catch(SQLException e){ + e.printStackTrace(); + } + return lastDeclined; + } + + public String getSchemName() { + return SchemName; + } + + public int getSchemOwner() { + return SchemOwner; + } + + public int getValidator() { + return Validator; + } + + public Timestamp getStartTime() { + return StartTime; + } + + public Timestamp getEndTime() { + return EndTime; + } + + public String getDeclineReason() { + return DeclineReason; + } +}