Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/commands/AllowTradingCommand.java

70 lines
3.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.users.Habbo;
2018-10-07 00:28:00 +02:00
import com.eu.habbo.messages.outgoing.users.UserPerksComposer;
2018-09-28 21:25:00 +02:00
2018-07-06 15:30:00 +02:00
import java.sql.Connection;
import java.sql.PreparedStatement;
2019-05-26 20:14:53 +02:00
public class AllowTradingCommand extends Command {
public AllowTradingCommand() {
2018-07-06 15:30:00 +02:00
super("cmd_allow_trading", Emulator.getTexts().getValue("commands.keys.cmd_allow_trading").split(";"));
}
@Override
2019-05-26 20:14:53 +02:00
public boolean handle(GameClient gameClient, String[] params) throws Exception {
if (params.length == 1) {
2018-07-06 15:30:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_allow_trading.forgot_username"));
return true;
}
2019-05-26 20:14:53 +02:00
if (params.length == 2) {
2018-07-06 15:30:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_allow_trading.forgot_trade").replace("%username%", params[1]));
return true;
}
2020-06-07 02:42:54 +02:00
final String username = params[1];
final String option = params[2];
2018-07-06 15:30:00 +02:00
2020-06-07 02:42:54 +02:00
if (option.equalsIgnoreCase(Emulator.getTexts().getValue("generic.yes")) || option.equalsIgnoreCase(Emulator.getTexts().getValue("generic.no"))) {
final boolean enabled = option.equalsIgnoreCase(Emulator.getTexts().getValue("generic.yes"));
final Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(username);
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2020-06-07 02:42:54 +02:00
if (!enabled) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET tradelock_amount = tradelock_amount + 1 WHERE user_id = ?")) {
statement.setInt(1, habbo.getHabboInfo().getId());
statement.executeUpdate();
}
}
2018-10-07 00:28:00 +02:00
habbo.getHabboStats().setAllowTrade(enabled);
2018-07-06 15:30:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_allow_trading." + (enabled ? "enabled" : "disabled")).replace("%username%", params[1]));
2018-10-07 00:28:00 +02:00
habbo.getClient().sendResponse(new UserPerksComposer(habbo));
2018-07-06 15:30:00 +02:00
return true;
2019-05-26 20:14:53 +02:00
} else {
2019-03-18 02:22:00 +01:00
boolean found;
2020-06-07 02:42:54 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("UPDATE users_settings INNER JOIN users ON users.id = users_settings.user_id SET can_trade = ?, tradelock_amount = tradelock_amount + ? WHERE users.username LIKE ?")) {
statement.setString(1, enabled ? "1" : "0");
statement.setInt(2, enabled ? 0 : 1);
statement.setString(3, username);
found = statement.executeUpdate() > 0;
}
2018-07-06 15:30:00 +02:00
2020-06-07 02:42:54 +02:00
if (!found) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_allow_trading.user_not_found").replace("%username%", params[1]));
return true;
2020-05-23 11:50:26 +02:00
}
2020-06-07 02:42:54 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_allow_trading." + (enabled ? "enabled" : "disabled")).replace("%username%", params[1]));
2018-07-06 15:30:00 +02:00
}
2020-06-07 02:42:54 +02:00
} else {
2018-07-06 15:30:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_allow_trading.incorrect_setting").replace("%enabled%", Emulator.getTexts().getValue("generic.yes")).replace("%disabled%", Emulator.getTexts().getValue("generic.no")));
}
return true;
}
}