mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-26 16:30:52 +01:00
Merge branch 'fix-catalog-voucher' into 'dev'
Cleanup redeem voucher See merge request morningstar/Arcturus-Community!480
This commit is contained in:
commit
b3ccc64a7e
@ -523,7 +523,6 @@ public class CatalogManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Voucher getVoucher(String code) {
|
||||
synchronized (this.vouchers) {
|
||||
for (Voucher voucher : this.vouchers) {
|
||||
@ -535,22 +534,20 @@ public class CatalogManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void redeemVoucher(GameClient client, String voucherCode) {
|
||||
Voucher voucher = Emulator.getGameEnvironment().getCatalogManager().getVoucher(voucherCode);
|
||||
Habbo habbo = client.getHabbo();
|
||||
if (habbo == null)
|
||||
return;
|
||||
|
||||
Voucher voucher = Emulator.getGameEnvironment().getCatalogManager().getVoucher(voucherCode);
|
||||
if (voucher == null) {
|
||||
client.sendResponse(new RedeemVoucherErrorComposer(RedeemVoucherErrorComposer.INVALID_CODE));
|
||||
return;
|
||||
}
|
||||
|
||||
Habbo habbo = client.getHabbo();
|
||||
if (habbo == null) return;
|
||||
|
||||
if (voucher.isExhausted()) {
|
||||
if (!Emulator.getGameEnvironment().getCatalogManager().deleteVoucher(voucher)) {
|
||||
client.sendResponse(new RedeemVoucherErrorComposer(RedeemVoucherErrorComposer.TECHNICAL_ERROR));
|
||||
}
|
||||
client.sendResponse(new RedeemVoucherErrorComposer(Emulator.getGameEnvironment().getCatalogManager().deleteVoucher(voucher) ? RedeemVoucherErrorComposer.INVALID_CODE : RedeemVoucherErrorComposer.TECHNICAL_ERROR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (voucher.hasUserExhausted(habbo.getHabboInfo().getId())) {
|
||||
@ -560,12 +557,6 @@ public class CatalogManager {
|
||||
|
||||
voucher.addHistoryEntry(habbo.getHabboInfo().getId());
|
||||
|
||||
if (voucher.isExhausted()) {
|
||||
if (!Emulator.getGameEnvironment().getCatalogManager().deleteVoucher(voucher)) {
|
||||
client.sendResponse(new RedeemVoucherErrorComposer(RedeemVoucherErrorComposer.TECHNICAL_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
if (voucher.points > 0) {
|
||||
client.getHabbo().getHabboInfo().addCurrencyAmount(voucher.pointsType, voucher.points);
|
||||
client.sendResponse(new UserPointsComposer(client.getHabbo().getHabboInfo().getCurrencyAmount(voucher.pointsType), voucher.points, voucher.pointsType));
|
||||
@ -578,7 +569,6 @@ public class CatalogManager {
|
||||
|
||||
if (voucher.catalogItemId > 0) {
|
||||
CatalogItem item = this.getCatalogItem(voucher.catalogItemId);
|
||||
|
||||
if (item != null) {
|
||||
this.purchaseItem(null, item, client.getHabbo(), 1, "", true);
|
||||
}
|
||||
@ -587,7 +577,6 @@ public class CatalogManager {
|
||||
client.sendResponse(new RedeemVoucherOKComposer());
|
||||
}
|
||||
|
||||
|
||||
public boolean deleteVoucher(Voucher voucher) {
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM vouchers WHERE code = ?")) {
|
||||
statement.setString(1, voucher.code);
|
||||
|
Loading…
Reference in New Issue
Block a user