Replace FredrickProcessor dependence on NoteDao
This commit is contained in:
@@ -9203,20 +9203,6 @@ public class Character extends AbstractCharacterObject {
|
||||
}
|
||||
}
|
||||
|
||||
public void changeName(String name) {
|
||||
FredrickProcessor.removeFredrickReminders(this.getId());
|
||||
|
||||
this.name = name;
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE `characters` SET `name` = ? WHERE `id` = ?")) {
|
||||
ps.setString(1, name);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getDoorSlot() {
|
||||
if (doorSlot != -1) {
|
||||
return doorSlot;
|
||||
|
||||
@@ -30,21 +30,18 @@ import client.inventory.InventoryType;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.ItemFactory;
|
||||
import client.inventory.manipulator.InventoryManipulator;
|
||||
import database.DaoException;
|
||||
import database.note.NoteDao;
|
||||
import model.Note;
|
||||
import net.server.Server;
|
||||
import net.server.world.World;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import server.ItemInformationProvider;
|
||||
import server.maps.HiredMerchant;
|
||||
import service.NoteService;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.PacketCreator;
|
||||
import tools.Pair;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -57,6 +54,12 @@ public class FredrickProcessor {
|
||||
private static final Logger log = LoggerFactory.getLogger(FredrickProcessor.class);
|
||||
private static final int[] dailyReminders = new int[]{2, 5, 10, 15, 30, 60, 90, Integer.MAX_VALUE};
|
||||
|
||||
private final NoteService noteService;
|
||||
|
||||
public FredrickProcessor(NoteService noteService) {
|
||||
this.noteService = noteService;
|
||||
}
|
||||
|
||||
private static byte canRetrieveFromFredrick(Character chr, List<Pair<Item, InventoryType>> items) {
|
||||
if (!Inventory.checkSpotsAndOwnership(chr, items)) {
|
||||
List<Integer> itemids = new LinkedList<>();
|
||||
@@ -130,10 +133,6 @@ public class FredrickProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeFredrickReminders(int cid) {
|
||||
removeFredrickReminders(Collections.singletonList(new Pair<>(cid, 0)));
|
||||
}
|
||||
|
||||
private static void removeFredrickReminders(List<Pair<Integer, Integer>> expiredCids) {
|
||||
List<String> expiredCnames = new LinkedList<>();
|
||||
for (Pair<Integer, Integer> id : expiredCids) {
|
||||
@@ -156,7 +155,7 @@ public class FredrickProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public static void runFredrickSchedule() {
|
||||
public void runFredrickSchedule() {
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
List<Pair<Integer, Integer>> expiredCids = new LinkedList<>();
|
||||
List<Pair<Pair<Integer, String>, Integer>> notifCids = new LinkedList<>();
|
||||
@@ -244,7 +243,7 @@ public class FredrickProcessor {
|
||||
ps.addBatch();
|
||||
|
||||
String msg = fredrickReminderMessage(cid.getRight() - 1);
|
||||
saveFredrickReminderNote(msg, cid.getLeft().getRight());
|
||||
noteService.sendNormal(msg, "FREDRICK", cid.getLeft().getRight());
|
||||
}
|
||||
|
||||
ps.executeBatch();
|
||||
@@ -255,15 +254,6 @@ 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` = ?")) {
|
||||
@@ -278,7 +268,7 @@ public class FredrickProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public static void fredrickRetrieveItems(Client c) { // thanks Gustav for pointing out the dupe on Fredrick handling
|
||||
public void fredrickRetrieveItems(Client c) { // thanks Gustav for pointing out the dupe on Fredrick handling
|
||||
if (c.tryacquireClient()) {
|
||||
try {
|
||||
Character chr = c.getPlayer();
|
||||
|
||||
Reference in New Issue
Block a user