2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.guilds;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class Guild implements Runnable {
|
|
|
|
public boolean needsUpdate;
|
|
|
|
public int lastRequested = Emulator.getIntUnixTimestamp();
|
2018-07-06 15:30:00 +02:00
|
|
|
private int id;
|
|
|
|
private int ownerId;
|
|
|
|
private String ownerName;
|
|
|
|
private String name;
|
|
|
|
private String description;
|
|
|
|
private int roomId;
|
|
|
|
private String roomName;
|
|
|
|
private GuildState state;
|
2019-05-12 07:35:08 +02:00
|
|
|
private boolean rights;
|
2018-07-06 15:30:00 +02:00
|
|
|
private int colorOne;
|
|
|
|
private int colorTwo;
|
|
|
|
private String badge;
|
|
|
|
private int dateCreated;
|
|
|
|
private int memberCount;
|
|
|
|
private int requestCount;
|
|
|
|
private boolean forum = false;
|
|
|
|
private SettingsState readForum = SettingsState.ADMINS;
|
|
|
|
private SettingsState postMessages = SettingsState.ADMINS;
|
|
|
|
private SettingsState postThreads = SettingsState.ADMINS;
|
|
|
|
private SettingsState modForum = SettingsState.ADMINS;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public Guild(ResultSet set) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.id = set.getInt("id");
|
|
|
|
this.ownerId = set.getInt("user_id");
|
|
|
|
this.ownerName = set.getString("username");
|
|
|
|
this.name = set.getString("name");
|
|
|
|
this.description = set.getString("description");
|
|
|
|
this.state = GuildState.values()[set.getInt("state")];
|
|
|
|
this.roomId = set.getInt("room_id");
|
|
|
|
this.roomName = set.getString("room_name");
|
2019-05-12 07:35:08 +02:00
|
|
|
this.rights = set.getString("rights").equalsIgnoreCase("1");
|
2018-07-06 15:30:00 +02:00
|
|
|
this.colorOne = set.getInt("color_one");
|
|
|
|
this.colorTwo = set.getInt("color_two");
|
|
|
|
this.badge = set.getString("badge");
|
|
|
|
this.dateCreated = set.getInt("date_created");
|
|
|
|
this.forum = set.getString("forum").equalsIgnoreCase("1");
|
|
|
|
this.readForum = SettingsState.valueOf(set.getString("read_forum"));
|
|
|
|
this.postMessages = SettingsState.valueOf(set.getString("post_messages"));
|
|
|
|
this.postThreads = SettingsState.valueOf(set.getString("post_threads"));
|
|
|
|
this.modForum = SettingsState.valueOf(set.getString("mod_forum"));
|
|
|
|
this.memberCount = 0;
|
|
|
|
this.requestCount = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public Guild(int ownerId, String ownerName, int roomId, String roomName, String name, String description, int colorOne, int colorTwo, String badge) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.id = 0;
|
|
|
|
this.ownerId = ownerId;
|
|
|
|
this.ownerName = ownerName;
|
|
|
|
this.roomId = roomId;
|
|
|
|
this.roomName = roomName;
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
this.state = GuildState.OPEN;
|
2019-05-12 07:35:08 +02:00
|
|
|
this.rights = false;
|
2018-07-06 15:30:00 +02:00
|
|
|
this.colorOne = colorOne;
|
|
|
|
this.colorTwo = colorTwo;
|
|
|
|
this.badge = badge;
|
|
|
|
this.memberCount = 0;
|
|
|
|
this.dateCreated = Emulator.getIntUnixTimestamp();
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void loadMemberCount() {
|
|
|
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
|
|
|
|
try (PreparedStatement statement = connection.prepareStatement("SELECT COUNT(id) as count FROM guilds_members WHERE level_id < 3 AND guild_id = ?")) {
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.setInt(1, this.id);
|
2019-05-26 20:14:53 +02:00
|
|
|
try (ResultSet set = statement.executeQuery()) {
|
|
|
|
if (set.next()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.memberCount = set.getInt(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try (PreparedStatement statement = connection.prepareStatement("SELECT COUNT(id) as count FROM guilds_members WHERE level_id = 3 AND guild_id = ?")) {
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.setInt(1, this.id);
|
2019-05-26 20:14:53 +02:00
|
|
|
try (ResultSet set = statement.executeQuery()) {
|
|
|
|
if (set.next()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.requestCount = set.getInt(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (SQLException e) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Emulator.getLogging().logSQLException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void run() {
|
|
|
|
if (this.needsUpdate) {
|
|
|
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds SET name = ?, description = ?, state = ?, rights = ?, color_one = ?, color_two = ?, badge = ?, read_forum = ?, post_messages = ?, post_threads = ?, mod_forum = ?, forum = ? WHERE id = ?")) {
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.setString(1, this.name);
|
|
|
|
statement.setString(2, this.description);
|
|
|
|
statement.setInt(3, this.state.state);
|
2019-05-12 07:35:08 +02:00
|
|
|
statement.setString(4, this.rights ? "1" : "0");
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.setInt(5, this.colorOne);
|
|
|
|
statement.setInt(6, this.colorTwo);
|
|
|
|
statement.setString(7, this.badge);
|
|
|
|
statement.setString(8, this.readForum.name());
|
|
|
|
statement.setString(9, this.postMessages.name());
|
|
|
|
statement.setString(10, this.postThreads.name());
|
|
|
|
statement.setString(11, this.modForum.name());
|
2019-05-11 00:45:07 +02:00
|
|
|
statement.setString(12, this.forum ? "1" : "0");
|
|
|
|
statement.setInt(13, this.id);
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.execute();
|
|
|
|
|
|
|
|
this.needsUpdate = false;
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (SQLException e) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Emulator.getLogging().logSQLException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getId() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.id;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setId(int id) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getOwnerName() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.ownerName;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getName() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setName(String name) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getDescription() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.description;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setDescription(String description) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getRoomId() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.roomId;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getRoomName() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.roomName;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setRoomName(String roomName) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.roomName = roomName;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public GuildState getState() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.state;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setState(GuildState state) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean getRights() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.rights;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setRights(boolean rights) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.rights = rights;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getColorOne() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.colorOne;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setColorOne(int colorOne) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.colorOne = colorOne;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getColorTwo() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.colorTwo;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setColorTwo(int colorTwo) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.colorTwo = colorTwo;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getBadge() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.badge;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setBadge(String badge) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.badge = badge;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getOwnerId() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.ownerId;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getDateCreated() {
|
2019-04-29 06:13:02 +02:00
|
|
|
return dateCreated;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getMemberCount() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.memberCount;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void increaseMemberCount() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.memberCount++;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void decreaseMemberCount() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.memberCount--;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getRequestCount() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.requestCount;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void increaseRequestCount() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.requestCount++;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void decreaseRequestCount() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.requestCount--;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean hasForum() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.forum;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setForum(boolean forum) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.forum = forum;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public SettingsState canReadForum() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.readForum;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setReadForum(SettingsState readForum) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.readForum = readForum;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public SettingsState canPostMessages() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.postMessages;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setPostMessages(SettingsState postMessages) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.postMessages = postMessages;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public SettingsState canPostThreads() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.postThreads;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setPostThreads(SettingsState postThreads) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.postThreads = postThreads;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public SettingsState canModForum() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.modForum;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setModForum(SettingsState modForum) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.modForum = modForum;
|
|
|
|
}
|
|
|
|
}
|