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