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:
@@ -8796,14 +8796,10 @@ public class Character extends AbstractCharacterObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendNote(String to, String msg, byte fame) throws SQLException {
|
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();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
|
PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
|
||||||
ps.setString(1, to);
|
ps.setString(1, to);
|
||||||
ps.setString(2, from);
|
ps.setString(2, this.getName());
|
||||||
ps.setString(3, msg);
|
ps.setString(3, msg);
|
||||||
ps.setLong(4, Server.getInstance().getCurrentTime());
|
ps.setLong(4, Server.getInstance().getCurrentTime());
|
||||||
ps.setByte(5, fame);
|
ps.setByte(5, fame);
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ import client.inventory.InventoryType;
|
|||||||
import client.inventory.Item;
|
import client.inventory.Item;
|
||||||
import client.inventory.ItemFactory;
|
import client.inventory.ItemFactory;
|
||||||
import client.inventory.manipulator.InventoryManipulator;
|
import client.inventory.manipulator.InventoryManipulator;
|
||||||
|
import database.DaoException;
|
||||||
|
import database.NoteDao;
|
||||||
|
import model.Note;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.world.World;
|
import net.server.world.World;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -241,7 +244,7 @@ public class FredrickProcessor {
|
|||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
|
|
||||||
String msg = fredrickReminderMessage(cid.getRight() - 1);
|
String msg = fredrickReminderMessage(cid.getRight() - 1);
|
||||||
Character.sendNote(cid.getLeft().getRight(), "FREDRICK", msg, (byte) 0);
|
saveFredrickReminderNote(msg, cid.getLeft().getRight());
|
||||||
}
|
}
|
||||||
|
|
||||||
ps.executeBatch();
|
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) {
|
private static boolean deleteFredrickItems(int cid) {
|
||||||
try (Connection con = DatabaseConnection.getConnection();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = con.prepareStatement("DELETE FROM `inventoryitems` WHERE `type` = ? AND `characterid` = ?")) {
|
PreparedStatement ps = con.prepareStatement("DELETE FROM `inventoryitems` WHERE `type` = ? AND `characterid` = ?")) {
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ package net.server.guild;
|
|||||||
import client.Character;
|
import client.Character;
|
||||||
import client.Client;
|
import client.Client;
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
|
import database.DaoException;
|
||||||
|
import database.NoteDao;
|
||||||
|
import model.Note;
|
||||||
import net.packet.Packet;
|
import net.packet.Packet;
|
||||||
import net.server.PlayerStorage;
|
import net.server.PlayerStorage;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
@@ -512,16 +515,7 @@ public class Guild {
|
|||||||
if (mgc.isOnline()) {
|
if (mgc.isOnline()) {
|
||||||
Server.getInstance().getWorld(mgc.getWorld()).setGuildAndRank(cid, 0, 5);
|
Server.getInstance().getWorld(mgc.getWorld()).setGuildAndRank(cid, 0, 5);
|
||||||
} else {
|
} else {
|
||||||
try (Connection con = DatabaseConnection.getConnection();
|
sendExpelledNote(initiator.getName(), mgc.getName());
|
||||||
PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`) VALUES (?, ?, ?, ?)")) {
|
|
||||||
ps.setString(1, mgc.getName());
|
|
||||||
ps.setString(2, initiator.getName());
|
|
||||||
ps.setString(3, "You have been expelled from the guild.");
|
|
||||||
ps.setLong(4, System.currentTimeMillis());
|
|
||||||
ps.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("expelMember - Guild", e);
|
|
||||||
}
|
|
||||||
Server.getInstance().getWorld(mgc.getWorld()).setOfflineGuildStatus((short) 0, (byte) 5, cid);
|
Server.getInstance().getWorld(mgc.getWorld()).setOfflineGuildStatus((short) 0, (byte) 5, cid);
|
||||||
}
|
}
|
||||||
} catch (Exception re) {
|
} catch (Exception re) {
|
||||||
@@ -537,6 +531,16 @@ public class Guild {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendExpelledNote(String expelledBy, String expelledChr) {
|
||||||
|
Note expelledNote = Note.createNormal("You have been expelled from the guild.", expelledBy, expelledChr,
|
||||||
|
System.currentTimeMillis());
|
||||||
|
try {
|
||||||
|
NoteDao.save(expelledNote);
|
||||||
|
} catch (DaoException e) {
|
||||||
|
log.error("Failed to save guild expel note - {} expelled from {} by {}", expelledChr, name, expelledBy, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void changeRank(int cid, int newRank) {
|
public void changeRank(int cid, int newRank) {
|
||||||
membersLock.lock();
|
membersLock.lock();
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user