Arcturus-Community/src/main/java/com/eu/habbo/messages/rcon/GivePixels.java

45 lines
1.4 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.messages.rcon;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo;
import com.google.gson.Gson;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class GivePixels extends RCONMessage<GivePixels.JSONGivePixels> {
2018-07-08 23:32:00 +02:00
2019-05-26 20:14:53 +02:00
public GivePixels() {
2018-07-06 15:30:00 +02:00
super(JSONGivePixels.class);
}
@Override
2019-05-26 20:14:53 +02:00
public void handle(Gson gson, JSONGivePixels object) {
2018-07-06 15:30:00 +02:00
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(object.user_id);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2018-07-06 15:30:00 +02:00
habbo.givePixels(object.pixels);
2019-05-26 20:14:53 +02:00
} else {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_currency SET users_currency.amount = users_currency.amount + ? WHERE users_currency.user_id = ? AND users_currency.type = 0")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, object.pixels);
statement.setInt(2, object.user_id);
statement.execute();
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2018-07-06 15:30:00 +02:00
this.status = RCONMessage.SYSTEM_ERROR;
2019-05-26 20:14:53 +02:00
Emulator.getLogging().logSQLException(e);
2018-07-06 15:30:00 +02:00
}
this.message = "offline";
}
}
2019-05-26 20:14:53 +02:00
static class JSONGivePixels {
2018-10-07 00:28:00 +02:00
public int user_id;
public int pixels;
2018-07-06 15:30:00 +02:00
}
}