Compare commits

..

4 Commits

Author SHA1 Message Date
Ponk
ecd155f2bb Merge pull request #201 from peamy/master #patch
BugFix: can't give CASH items to player (prepareInventoryItemList)
2023-11-08 20:50:50 +01:00
remsus
d6147d5191 Fix preparation of invList (CASH was skipped) in prepareInventoryItemList (AbstractPlayerInteraction) 2023-11-08 11:26:55 +01:00
Ponk
7ef471f1e2 Merge pull request #197 from wangxiaobao0851/fix-mts #patch
Fix MTS sql syntax error and month error
2023-11-07 17:28:16 +01:00
王小宝
c3404d296a Fix MTS sql syntax error and month error 2023-10-13 21:16:40 +08:00
3 changed files with 18 additions and 39 deletions

View File

@@ -45,6 +45,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
@@ -122,40 +124,12 @@ public final class MTSHandler extends AbstractPacketHandler {
return;
}
}
Calendar calendar = Calendar.getInstance();
int year;
int month;
int day;
int oldmax = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int oldday = calendar.get(Calendar.DAY_OF_MONTH) + 7;
if (oldmax < oldday) {
if (calendar.get(Calendar.MONTH) + 2 > 12) {
year = calendar.get(Calendar.YEAR) + 1;
month = 1;
calendar.set(year, month, 1);
day = oldday - oldmax;
} else {
month = calendar.get(Calendar.MONTH) + 2;
year = calendar.get(Calendar.YEAR);
calendar.set(year, month, 1);
day = oldday - oldmax;
}
} else {
day = calendar.get(Calendar.DAY_OF_MONTH) + 7;
month = calendar.get(Calendar.MONTH);
year = calendar.get(Calendar.YEAR);
}
String date = year + "-";
if (month < 10) {
date += "0" + month + "-";
} else {
date += month + "-";
}
if (day < 10) {
date += "0" + day;
} else {
date += day + "";
}
LocalDate now = LocalDate.now();
LocalDate sellEnd = now.plusDays(7);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String date = sellEnd.format(formatter);
if (!i.getInventoryType().equals(InventoryType.EQUIP)) {
Item item = i;
try (PreparedStatement pse = con.prepareStatement("INSERT INTO mts_items (tab, type, itemid, quantity, expiration, giftFrom, seller, price, owner, sellername, sell_ends) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
@@ -761,7 +735,7 @@ public final class MTSHandler extends AbstractPacketHandler {
}
}
}
try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE tab = ? " + (type != 0 ? "AND type = ?" : "") + "AND transfer = 0")) {
try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE tab = ? " + (type != 0 ? "AND type = ?" : "") + " AND transfer = 0")) {
ps.setInt(1, tab);
if (type != 0) {
ps.setInt(2, type);

View File

@@ -291,7 +291,7 @@ public class AbstractPlayerInteraction {
int size = Math.min(itemids.size(), quantity.size());
List<List<Pair<Integer, Integer>>> invList = new ArrayList<>(6);
for (int i = InventoryType.UNDEFINED.getType(); i < InventoryType.CASH.getType(); i++) {
for (int i = InventoryType.UNDEFINED.getType(); i <= InventoryType.CASH.getType(); i++) {
invList.add(new LinkedList<>());
}

View File

@@ -23,6 +23,8 @@ package server;
import client.inventory.Item;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
/**
@@ -38,13 +40,16 @@ public class MTSItemInfo {
private int day = 1;
public MTSItemInfo(Item item, int price, int id, int cid, String seller, String date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate sellEnd = LocalDate.parse(date, formatter);
this.item = item;
this.price = price;
this.seller = seller;
this.id = id;
this.year = Integer.parseInt(date.substring(0, 4));
this.month = Integer.parseInt(date.substring(5, 7));
this.day = Integer.parseInt(date.substring(8, 10));
this.year = sellEnd.getYear();
this.month = sellEnd.getMonthValue();
this.day = sellEnd.getDayOfMonth();
}
public Item getItem() {