Clean up code, fix bug showing it succeeded while it didn't

This commit is contained in:
Mike 2020-06-03 04:26:07 +02:00
parent d2d3dcc78c
commit 5b52ece5e3
5 changed files with 44 additions and 41 deletions

View File

@ -11,5 +11,5 @@ INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_softki
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_softkick_error_self', 'You can not softkick yourself!');
-- Rank ignoring
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('generic.error.higher_rank', 'You can\'t ignore this user.');
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.ignore.staffs', '0');
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('generic.error.ignore_higher_rank', 'You can\'t ignore this user.');
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.allow.ignore.staffs', '1');

View File

@ -603,26 +603,27 @@ public class HabboStats implements Runnable {
return 0;
}
public void ignoreUser(GameClient gameClient, int userId) {
Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
if (!Emulator.getConfig().getBoolean("hotel.ignore.staffs")) {
if (target.getHabboInfo().getRank().getId() >= gameClient.getHabbo().getHabboInfo().getRank().getId()) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.higher_rank"), RoomChatMessageBubbles.ALERT);
} else if (!this.userIgnored(userId)) {
this.ignoredUsers.add(userId);
/**
* Ignore an user.
*
* @param gameClient The client to which this HabboStats instance belongs.
* @param userId The user to ignore.
* @return true if successfully ignored, false otherwise.
*/
public boolean ignoreUser(GameClient gameClient, int userId) {
final Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) {
statement.setInt(1, this.habboInfo.getId());
statement.setInt(2, userId);
statement.execute();
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
}
if (!Emulator.getConfig().getBoolean("hotel.allow.ignore.staffs")) {
final int ownRank = gameClient.getHabbo().getHabboInfo().getRank().getId();
final int targetRank = target.getHabboInfo().getRank().getId();
if (targetRank >= ownRank) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.ignore_higher_rank"), RoomChatMessageBubbles.ALERT);
return false;
}
}
else if (!this.userIgnored(userId)) {
if (!this.userIgnored(userId)) {
this.ignoredUsers.add(userId);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
@ -635,6 +636,7 @@ public class HabboStats implements Runnable {
}
}
return true;
}
public void unignoreUser(int userId) {

View File

@ -73,9 +73,10 @@ public class ReportEvent extends MessageHandler {
Emulator.getThreading().run(() -> {
if (issue.state == ModToolTicketState.OPEN) {
if (cfhTopic.action == CfhActionType.AUTO_IGNORE) {
ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(reported.getHabboInfo().getId());
if (ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(ReportEvent.this.client, reported.getHabboInfo().getId())) {
ReportEvent.this.client.sendResponse(new RoomUserIgnoredComposer(reported, RoomUserIgnoredComposer.IGNORED));
}
}
ReportEvent.this.client.sendResponse(new ModToolIssueHandledComposer(cfhTopic.reply).compose());
Emulator.getGameEnvironment().getModToolManager().closeTicketAsHandled(issue, null);
@ -99,12 +100,13 @@ public class ReportEvent extends MessageHandler {
Emulator.getThreading().run(() -> {
if (issue.state == ModToolTicketState.OPEN) {
if (cfhTopic.action == CfhActionType.AUTO_IGNORE) {
ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(issue.reportedId);
if (ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(ReportEvent.this.client, issue.reportedId)) {
Habbo reported = Emulator.getGameEnvironment().getHabboManager().getHabbo(issue.reportedId);
if (reported != null) {
ReportEvent.this.client.sendResponse(new RoomUserIgnoredComposer(reported, RoomUserIgnoredComposer.IGNORED));
}
}
}
ReportEvent.this.client.sendResponse(new ModToolIssueHandledComposer(cfhTopic.reply).compose());
Emulator.getGameEnvironment().getModToolManager().closeTicketAsHandled(issue, null);

View File

@ -21,8 +21,7 @@ public class IgnoreRoomUserEvent extends MessageHandler {
if (habbo == this.client.getHabbo())
return;
{
this.client.getHabbo().getHabboStats().ignoreUser(habbo.getHabboInfo().getId());
if (this.client.getHabbo().getHabboStats().ignoreUser(this.client, habbo.getHabboInfo().getId())) {
this.client.sendResponse(new RoomUserIgnoredComposer(habbo, RoomUserIgnoredComposer.IGNORED));
AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("SelfModIgnoreSeen"));
}

View File

@ -22,7 +22,7 @@ public class IgnoreUser extends RCONMessage<IgnoreUser.JSONIgnoreUser> {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(object.user_id);
if (habbo != null) {
habbo.getHabboStats().ignoreUser(object.target_id);
habbo.getHabboStats().ignoreUser(habbo.getClient(), object.target_id);
} else {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) {