Rework sending notes to chr, get rid of the first method

Sending notes should not be the handled by Character
This commit is contained in:
P0nk
2022-12-26 17:03:40 +01:00
parent 1f4ce98998
commit 4d480660b5
3 changed files with 28 additions and 16 deletions

View File

@@ -8796,14 +8796,10 @@ public class Character extends AbstractCharacterObject {
}
public void sendNote(String to, String msg, byte fame) throws SQLException {
sendNote(to, this.getName(), msg, fame);
}
public static void sendNote(String to, String from, String msg, byte fame) throws SQLException {
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
ps.setString(1, to);
ps.setString(2, from);
ps.setString(2, this.getName());
ps.setString(3, msg);
ps.setLong(4, Server.getInstance().getCurrentTime());
ps.setByte(5, fame);

View File

@@ -30,6 +30,9 @@ import client.inventory.InventoryType;
import client.inventory.Item;
import client.inventory.ItemFactory;
import client.inventory.manipulator.InventoryManipulator;
import database.DaoException;
import database.NoteDao;
import model.Note;
import net.server.Server;
import net.server.world.World;
import org.slf4j.Logger;
@@ -241,7 +244,7 @@ public class FredrickProcessor {
ps.addBatch();
String msg = fredrickReminderMessage(cid.getRight() - 1);
Character.sendNote(cid.getLeft().getRight(), "FREDRICK", msg, (byte) 0);
saveFredrickReminderNote(msg, cid.getLeft().getRight());
}
ps.executeBatch();
@@ -252,6 +255,15 @@ public class FredrickProcessor {
}
}
private static void saveFredrickReminderNote(String message, String to) {
Note reminderNote = Note.createNormal(message, "FREDRICK", to, Server.getInstance().getCurrentTime());
try {
NoteDao.save(reminderNote);
} catch (DaoException e) {
log.error("Failed to save Fredrick reminder note", e);
}
}
private static boolean deleteFredrickItems(int cid) {
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM `inventoryitems` WHERE `type` = ? AND `characterid` = ?")) {