Support for custom mail manager.
This commit is contained in:
@ -113,6 +113,7 @@ public final class Config
|
||||
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
|
||||
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
|
||||
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
|
||||
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
|
||||
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
|
||||
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
|
||||
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
|
||||
@ -1104,6 +1105,8 @@ public final class Config
|
||||
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
|
||||
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
|
||||
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
|
||||
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
|
||||
public static int CUSTOM_MAIL_MANAGER_DELAY;
|
||||
public static boolean FACTION_SYSTEM_ENABLED;
|
||||
public static Location FACTION_STARTING_LOCATION;
|
||||
public static Location FACTION_MANAGER_LOCATION;
|
||||
@ -2454,6 +2457,12 @@ public final class Config
|
||||
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
|
||||
}
|
||||
|
||||
// Load CustomMailManager config file (if exists)
|
||||
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
|
||||
|
||||
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
|
||||
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
|
||||
|
||||
// Load DualboxCheck config file (if exists)
|
||||
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);
|
||||
|
||||
|
@ -117,6 +117,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.FactionManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
|
||||
@ -414,6 +415,10 @@ public class GameServer
|
||||
{
|
||||
MailManager.getInstance();
|
||||
}
|
||||
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
|
||||
{
|
||||
CustomMailManager.getInstance();
|
||||
}
|
||||
|
||||
PunishmentManager.getInstance();
|
||||
|
||||
|
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.instancemanager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.enums.MailType;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.entity.Message;
|
||||
import com.l2jmobius.gameserver.model.holders.ItemHolder;
|
||||
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class CustomMailManager
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
|
||||
|
||||
// SQL Statements
|
||||
private static final String READ_SQL = "SELECT * FROM custom_mail";
|
||||
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
|
||||
|
||||
protected CustomMailManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
Statement ps = con.createStatement();
|
||||
ResultSet rs = ps.executeQuery(READ_SQL))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int playerId = rs.getInt("receiver");
|
||||
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
|
||||
if ((player != null) && player.isOnline())
|
||||
{
|
||||
// Create message.
|
||||
final String items = rs.getString("items");
|
||||
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
|
||||
final List<ItemHolder> itemHolders = new ArrayList<>();
|
||||
for (String str : items.split(";"))
|
||||
{
|
||||
if (str.toLowerCase().contains(" "))
|
||||
{
|
||||
final String itemId = str.toLowerCase().split(" ")[0];
|
||||
final String itemCount = str.toLowerCase().split(" ")[1];
|
||||
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
|
||||
{
|
||||
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
|
||||
}
|
||||
}
|
||||
else if (Util.isDigit(str))
|
||||
{
|
||||
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
|
||||
}
|
||||
}
|
||||
if (!itemHolders.isEmpty())
|
||||
{
|
||||
final Mail attachments = msg.createAttachments();
|
||||
for (ItemHolder itemHolder : itemHolders)
|
||||
{
|
||||
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete entry from database.
|
||||
try (Connection con2 = DatabaseFactory.getConnection();
|
||||
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
|
||||
{
|
||||
stmt.setString(1, rs.getString("date"));
|
||||
stmt.setInt(2, playerId);
|
||||
stmt.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
|
||||
}
|
||||
|
||||
// Send message.
|
||||
MailManager.getInstance().sendMessage(msg);
|
||||
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
|
||||
}
|
||||
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
|
||||
|
||||
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
|
||||
}
|
||||
|
||||
public static CustomMailManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final CustomMailManager INSTANCE = new CustomMailManager();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user