134 lines
3.4 KiB
Java
134 lines
3.4 KiB
Java
package net.saltymc.eaa.util.database;
|
|
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
public class DB_Tag {
|
|
|
|
public static final String tableName = "Tag";
|
|
|
|
int id;
|
|
DB_Player player;
|
|
int grade;
|
|
Type type;
|
|
|
|
Date tagDate;
|
|
|
|
public DB_Tag(DB_Player db_player){
|
|
this.player = db_player;
|
|
}
|
|
|
|
public DB_Tag(DB_Player db_player, Type type, int grade){
|
|
this.player = db_player;
|
|
this.type = type;
|
|
this.grade = grade;
|
|
}
|
|
|
|
public void put(){
|
|
putTag(this);
|
|
}
|
|
|
|
public static void putTag(DB_Tag tag){
|
|
try {
|
|
PreparedStatement statement = Postgre.getStatement(
|
|
"INSERT INTO " + tableName + " (Player_ID, Grade, TagType, TagDate) " +
|
|
"VALUES (?, ?, ?, ?);");
|
|
|
|
statement.setInt(1, tag.player.getId());
|
|
statement.setInt(2,tag.grade);
|
|
statement.setString(3, tag.type.name());
|
|
statement.setDate(4 , new java.sql.Date(new Date().getTime()));
|
|
|
|
statement.execute();
|
|
} catch (SQLException e){
|
|
throw new RuntimeException("Could not save Tag!", e);
|
|
}
|
|
}
|
|
|
|
public static List<DB_Tag> getTagsFromPlayer(DB_Player player){
|
|
if (player == null)
|
|
return new ArrayList<>();
|
|
|
|
try {
|
|
PreparedStatement statement = Postgre.getStatement("SELECT * FROM " + tableName + " WHERE Player_ID = ? ORDER BY TagDate ASC;");
|
|
statement.setInt(1, player.getId());
|
|
|
|
ResultSet rs = statement.executeQuery();
|
|
List<DB_Tag> ret = new ArrayList<>();
|
|
while (rs.next()){
|
|
DB_Tag tmp = new DB_Tag(player);
|
|
tmp.id = rs.getInt("ID");
|
|
tmp.grade = rs.getInt("Grade");
|
|
tmp.type = Type.valueOf(rs.getString("TagType"));
|
|
tmp.tagDate = rs.getDate("TagDate");
|
|
|
|
ret.add(tmp);
|
|
}
|
|
|
|
return ret;
|
|
|
|
} catch (SQLException e){
|
|
throw new RuntimeException("Error getting Tag!", e);
|
|
}
|
|
}
|
|
|
|
public DB_Player getPlayer() {
|
|
return player;
|
|
}
|
|
|
|
public int getGrade() {
|
|
return grade;
|
|
}
|
|
|
|
public Type getType() {
|
|
return type;
|
|
}
|
|
|
|
public Date getTagDate() {
|
|
return tagDate;
|
|
}
|
|
|
|
public enum Type {
|
|
HACKER(
|
|
"HAX", "PLayer who hacks", 0xaa0000
|
|
), FRIENDLY(
|
|
"FND", "Player you like", 0x55ff55
|
|
), GOODPLAYER(
|
|
"PRO", "Fair player with good skill", 0xffaa00
|
|
), IDIOT(
|
|
"A$$", "Person who is annoying and bad", 0x55ffff
|
|
), NOOB(
|
|
"BAD", "Person with low skill", 0xff55ff
|
|
), NOTTAGGED(
|
|
"NaN", "Player is not tagged", 0x555555
|
|
), NOTLOADED(
|
|
"---", "PLayer not loaded", 0xffffff
|
|
);
|
|
|
|
String tag, description;
|
|
int color;
|
|
|
|
Type(String tag, String description, int color){
|
|
this.tag = tag;
|
|
this.description = description;
|
|
this.color = color;
|
|
}
|
|
|
|
public String getTag() {
|
|
return tag;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public int getColor() {
|
|
return color;
|
|
}
|
|
}
|
|
}
|