Sync with L2jServer HighFive Mar 25th 2015.

This commit is contained in:
MobiusDev
2015-03-25 06:48:51 +00:00
parent e0c66b1412
commit 82606870c0
194 changed files with 2619 additions and 2869 deletions

View File

@@ -28,11 +28,10 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import com.l2jserver.Config;
@@ -76,14 +75,14 @@ public class Hero
// delete hero items
private static final String DELETE_ITEMS = "DELETE FROM items WHERE item_id IN (6842, 6611, 6612, 6613, 6614, 6615, 6616, 6617, 6618, 6619, 6620, 6621, 9388, 9389, 9390) AND owner_id NOT IN (SELECT charId FROM characters WHERE accesslevel > 0)";
private static final Map<Integer, StatsSet> _heroes = new HashMap<>();
private static final Map<Integer, StatsSet> _completeHeroes = new HashMap<>();
private static final Map<Integer, StatsSet> HEROES = new ConcurrentHashMap<>();
private static final Map<Integer, StatsSet> COMPLETE_HEROS = new ConcurrentHashMap<>();
private static final Map<Integer, StatsSet> _herocounts = new HashMap<>();
private static final Map<Integer, List<StatsSet>> _herofights = new HashMap<>();
private static final Map<Integer, StatsSet> HERO_COUNTS = new ConcurrentHashMap<>();
private static final Map<Integer, List<StatsSet>> HERO_FIGHTS = new ConcurrentHashMap<>();
private static final Map<Integer, List<StatsSet>> _herodiary = new HashMap<>();
private static final Map<Integer, String> _heroMessage = new HashMap<>();
private static final Map<Integer, List<StatsSet>> HERO_DIARY = new ConcurrentHashMap<>();
private static final Map<Integer, String> HERO_MESSAGE = new ConcurrentHashMap<>();
public static final String COUNT = "count";
public static final String PLAYED = "played";
@@ -97,11 +96,6 @@ public class Hero
public static final int ACTION_HERO_GAINED = 2;
public static final int ACTION_CASTLE_TAKEN = 3;
public static Hero getInstance()
{
return SingletonHolder._instance;
}
protected Hero()
{
init();
@@ -109,12 +103,12 @@ public class Hero
private void init()
{
_heroes.clear();
_completeHeroes.clear();
_herocounts.clear();
_herofights.clear();
_herodiary.clear();
_heroMessage.clear();
HEROES.clear();
COMPLETE_HEROS.clear();
HERO_COUNTS.clear();
HERO_FIGHTS.clear();
HERO_DIARY.clear();
HERO_MESSAGE.clear();
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
Statement s1 = con.createStatement();
@@ -139,7 +133,7 @@ public class Hero
processHeros(ps, charId, hero);
_heroes.put(charId, hero);
HEROES.put(charId, hero);
}
while (rset2.next())
@@ -154,16 +148,16 @@ public class Hero
processHeros(ps, charId, hero);
_completeHeroes.put(charId, hero);
COMPLETE_HEROS.put(charId, hero);
}
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Hero System: Couldnt load Heroes", e);
_log.warning("Hero System: Couldnt load Heroes: " + e.getMessage());
}
_log.info("Hero System: Loaded " + _heroes.size() + " Heroes.");
_log.info("Hero System: Loaded " + _completeHeroes.size() + " all time Heroes.");
_log.info("Hero System: Loaded " + HEROES.size() + " Heroes.");
_log.info("Hero System: Loaded " + COMPLETE_HEROS.size() + " all time Heroes.");
}
private void processHeros(PreparedStatement ps, int charId, StatsSet hero) throws SQLException
@@ -222,19 +216,19 @@ public class Hero
{
if (rset.next())
{
_heroMessage.put(charId, rset.getString("message"));
HERO_MESSAGE.put(charId, rset.getString("message"));
}
}
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Hero System: Couldnt load Hero Message for CharId: " + charId, e);
_log.warning("Hero System: Couldnt load Hero Message for CharId: " + charId + ": " + e.getMessage());
}
}
public void loadDiary(int charId)
{
final List<StatsSet> _diary = new ArrayList<>();
final List<StatsSet> diary = new ArrayList<>();
int diaryentries = 0;
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT * FROM heroes_diary WHERE charId=? ORDER BY time ASC"))
@@ -273,31 +267,31 @@ public class Hero
_diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
}
}
_diary.add(_diaryentry);
diary.add(_diaryentry);
diaryentries++;
}
}
_herodiary.put(charId, _diary);
HERO_DIARY.put(charId, diary);
_log.info("Hero System: Loaded " + diaryentries + " diary entries for Hero: " + CharNameTable.getInstance().getNameById(charId));
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Hero System: Couldnt load Hero Diary for CharId: " + charId, e);
_log.warning("Hero System: Couldnt load Hero Diary for CharId: " + charId + ": " + e.getMessage());
}
}
public void loadFights(int charId)
{
final List<StatsSet> _fights = new ArrayList<>();
StatsSet _herocountdata = new StatsSet();
Calendar _data = Calendar.getInstance();
_data.set(Calendar.DAY_OF_MONTH, 1);
_data.set(Calendar.HOUR_OF_DAY, 0);
_data.set(Calendar.MINUTE, 0);
_data.set(Calendar.MILLISECOND, 0);
final List<StatsSet> fights = new ArrayList<>();
StatsSet heroCountData = new StatsSet();
Calendar data = Calendar.getInstance();
data.set(Calendar.DAY_OF_MONTH, 1);
data.set(Calendar.HOUR_OF_DAY, 0);
data.set(Calendar.MINUTE, 0);
data.set(Calendar.MILLISECOND, 0);
long from = _data.getTimeInMillis();
long from = data.getTimeInMillis();
int numberoffights = 0;
int _victorys = 0;
int _losses = 0;
@@ -361,7 +355,7 @@ public class Hero
_draws++;
}
_fights.add(fight);
fights.add(fight);
numberoffights++;
}
@@ -397,7 +391,7 @@ public class Hero
_draws++;
}
_fights.add(fight);
fights.add(fight);
numberoffights++;
}
@@ -405,29 +399,29 @@ public class Hero
}
}
_herocountdata.set("victory", _victorys);
_herocountdata.set("draw", _draws);
_herocountdata.set("loss", _losses);
heroCountData.set("victory", _victorys);
heroCountData.set("draw", _draws);
heroCountData.set("loss", _losses);
_herocounts.put(charId, _herocountdata);
_herofights.put(charId, _fights);
HERO_COUNTS.put(charId, heroCountData);
HERO_FIGHTS.put(charId, fights);
_log.info("Hero System: Loaded " + numberoffights + " fights for Hero: " + CharNameTable.getInstance().getNameById(charId));
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Hero System: Couldnt load Hero fights history for CharId: " + charId, e);
_log.warning("Hero System: Couldnt load Hero fights history for CharId: " + charId + ": " + e);
}
}
public Map<Integer, StatsSet> getHeroes()
{
return _heroes;
return HEROES;
}
public int getHeroByClass(int classid)
{
for (Entry<Integer, StatsSet> e : _heroes.entrySet())
for (Entry<Integer, StatsSet> e : HEROES.entrySet())
{
if (e.getValue().getInt(Olympiad.CLASS_ID) == classid)
{
@@ -439,42 +433,42 @@ public class Hero
public void resetData()
{
_herodiary.clear();
_herofights.clear();
_herocounts.clear();
_heroMessage.clear();
HERO_DIARY.clear();
HERO_FIGHTS.clear();
HERO_COUNTS.clear();
HERO_MESSAGE.clear();
}
public void showHeroDiary(L2PcInstance activeChar, int heroclass, int charid, int page)
{
final int perpage = 10;
if (_herodiary.containsKey(charid))
final List<StatsSet> mainList = HERO_DIARY.get(charid);
if (mainList != null)
{
List<StatsSet> _mainlist = _herodiary.get(charid);
final NpcHtmlMessage DiaryReply = new NpcHtmlMessage();
final NpcHtmlMessage diaryReply = new NpcHtmlMessage();
final String htmContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/olympiad/herodiary.htm");
if ((htmContent != null) && _heroMessage.containsKey(charid))
final String heroMessage = HERO_MESSAGE.get(charid);
if ((htmContent != null) && (heroMessage != null))
{
DiaryReply.setHtml(htmContent);
DiaryReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));
DiaryReply.replace("%message%", _heroMessage.get(charid));
DiaryReply.disableValidation();
diaryReply.setHtml(htmContent);
diaryReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));
diaryReply.replace("%message%", heroMessage);
diaryReply.disableValidation();
if (!_mainlist.isEmpty())
if (!mainList.isEmpty())
{
final ArrayList<StatsSet> _list = new ArrayList<>();
_list.addAll(_mainlist);
Collections.reverse(_list);
final List<StatsSet> list = new ArrayList<>(mainList);
Collections.reverse(list);
boolean color = true;
final StringBuilder fList = new StringBuilder(500);
int counter = 0;
int breakat = 0;
for (int i = ((page - 1) * perpage); i < _list.size(); i++)
for (int i = ((page - 1) * perpage); i < list.size(); i++)
{
breakat = i;
StatsSet _diaryentry = _list.get(i);
StatsSet diaryEntry = list.get(i);
StringUtil.append(fList, "<tr><td>");
if (color)
{
@@ -484,8 +478,8 @@ public class Hero
{
StringUtil.append(fList, "<table width=270>");
}
StringUtil.append(fList, "<tr><td width=270><font color=\"LEVEL\">" + _diaryentry.getString("date") + ":xx</font></td></tr>");
StringUtil.append(fList, "<tr><td width=270>" + _diaryentry.getString("action") + "</td></tr>");
StringUtil.append(fList, "<tr><td width=270><font color=\"LEVEL\">" + diaryEntry.getString("date") + ":xx</font></td></tr>");
StringUtil.append(fList, "<tr><td width=270>" + diaryEntry.getString("action") + "</td></tr>");
StringUtil.append(fList, "<tr><td>&nbsp;</td></tr></table>");
StringUtil.append(fList, "</td></tr>");
color = !color;
@@ -496,34 +490,34 @@ public class Hero
}
}
if (breakat < (_list.size() - 1))
if (breakat < (list.size() - 1))
{
DiaryReply.replace("%buttprev%", "<button value=\"Prev\" action=\"bypass _diary?class=" + heroclass + "&page=" + (page + 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
diaryReply.replace("%buttprev%", "<button value=\"Prev\" action=\"bypass _diary?class=" + heroclass + "&page=" + (page + 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
}
else
{
DiaryReply.replace("%buttprev%", "");
diaryReply.replace("%buttprev%", "");
}
if (page > 1)
{
DiaryReply.replace("%buttnext%", "<button value=\"Next\" action=\"bypass _diary?class=" + heroclass + "&page=" + (page - 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
diaryReply.replace("%buttnext%", "<button value=\"Next\" action=\"bypass _diary?class=" + heroclass + "&page=" + (page - 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
}
else
{
DiaryReply.replace("%buttnext%", "");
diaryReply.replace("%buttnext%", "");
}
DiaryReply.replace("%list%", fList.toString());
diaryReply.replace("%list%", fList.toString());
}
else
{
DiaryReply.replace("%list%", "");
DiaryReply.replace("%buttprev%", "");
DiaryReply.replace("%buttnext%", "");
diaryReply.replace("%list%", "");
diaryReply.replace("%buttprev%", "");
diaryReply.replace("%buttnext%", "");
}
activeChar.sendPacket(DiaryReply);
activeChar.sendPacket(diaryReply);
}
}
}
@@ -535,10 +529,9 @@ public class Hero
int _loss = 0;
int _draw = 0;
if (_herofights.containsKey(charid))
final List<StatsSet> heroFights = HERO_FIGHTS.get(charid);
if (heroFights != null)
{
List<StatsSet> _list = _herofights.get(charid);
final NpcHtmlMessage FightReply = new NpcHtmlMessage();
final String htmContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/olympiad/herohistory.htm");
if (htmContent != null)
@@ -546,24 +539,24 @@ public class Hero
FightReply.setHtml(htmContent);
FightReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));
if (!_list.isEmpty())
if (!heroFights.isEmpty())
{
if (_herocounts.containsKey(charid))
final StatsSet heroCount = HERO_COUNTS.get(charid);
if (heroCount != null)
{
StatsSet _herocount = _herocounts.get(charid);
_win = _herocount.getInt("victory");
_loss = _herocount.getInt("loss");
_draw = _herocount.getInt("draw");
_win = heroCount.getInt("victory");
_loss = heroCount.getInt("loss");
_draw = heroCount.getInt("draw");
}
boolean color = true;
final StringBuilder fList = new StringBuilder(500);
int counter = 0;
int breakat = 0;
for (int i = ((page - 1) * perpage); i < _list.size(); i++)
for (int i = ((page - 1) * perpage); i < heroFights.size(); i++)
{
breakat = i;
StatsSet fight = _list.get(i);
StatsSet fight = heroFights.get(i);
StringUtil.append(fList, "<tr><td>");
if (color)
{
@@ -585,7 +578,7 @@ public class Hero
}
}
if (breakat < (_list.size() - 1))
if (breakat < (heroFights.size() - 1))
{
FightReply.replace("%buttprev%", "<button value=\"Prev\" action=\"bypass _match?class=" + heroclass + "&page=" + (page + 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
}
@@ -625,7 +618,7 @@ public class Hero
{
updateHeroes(true);
for (Integer objectId : _heroes.keySet())
for (Integer objectId : HEROES.keySet())
{
final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
if (player == null)
@@ -662,26 +655,27 @@ public class Hero
player.broadcastUserInfo();
}
deleteItemsInDb();
HEROES.clear();
if (newHeroes.isEmpty())
{
_heroes.clear();
return;
}
Map<Integer, StatsSet> heroes = new HashMap<>();
for (StatsSet hero : newHeroes)
{
int charId = hero.getInt(Olympiad.CHAR_ID);
if ((_completeHeroes != null) && _completeHeroes.containsKey(charId))
if (COMPLETE_HEROS.containsKey(charId))
{
StatsSet oldHero = _completeHeroes.get(charId);
StatsSet oldHero = COMPLETE_HEROS.get(charId);
int count = oldHero.getInt(COUNT);
oldHero.set(COUNT, count + 1);
oldHero.set(PLAYED, 1);
oldHero.set(CLAIMED, false);
heroes.put(charId, oldHero);
HEROES.put(charId, oldHero);
}
else
{
@@ -691,17 +685,10 @@ public class Hero
newHero.set(COUNT, 1);
newHero.set(PLAYED, 1);
newHero.set(CLAIMED, false);
heroes.put(charId, newHero);
HEROES.put(charId, newHero);
}
}
deleteItemsInDb();
_heroes.clear();
_heroes.putAll(heroes);
heroes.clear();
updateHeroes(false);
}
@@ -720,11 +707,11 @@ public class Hero
{
StatsSet hero;
int heroId;
for (Entry<Integer, StatsSet> entry : _heroes.entrySet())
for (Entry<Integer, StatsSet> entry : HEROES.entrySet())
{
hero = entry.getValue();
heroId = entry.getKey();
if (_completeHeroes.isEmpty() || !_completeHeroes.containsKey(heroId))
if (!COMPLETE_HEROS.containsKey(heroId))
{
try (PreparedStatement insert = con.prepareStatement(INSERT_HERO))
{
@@ -771,9 +758,9 @@ public class Hero
}
}
}
_heroes.put(heroId, hero);
HEROES.put(heroId, hero);
_completeHeroes.put(heroId, hero);
COMPLETE_HEROS.put(heroId, hero);
}
else
{
@@ -791,7 +778,7 @@ public class Hero
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Hero System: Couldnt update Heroes", e);
_log.warning("Hero System: Couldnt update Heroes: " + e.getMessage());
}
}
@@ -804,23 +791,17 @@ public class Hero
{
setDiaryData(charId, ACTION_RAID_KILLED, npcId);
L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId);
if (_herodiary.containsKey(charId) && (template != null))
final L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId);
final List<StatsSet> list = HERO_DIARY.get(charId);
if ((list != null) && (template != null))
{
// Get Data
List<StatsSet> _list = _herodiary.get(charId);
// Clear old data
_herodiary.remove(charId);
// Prepare new data
StatsSet _diaryentry = new StatsSet();
String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
_diaryentry.set("date", date);
_diaryentry.set("action", template.getName() + " was defeated");
final StatsSet diaryEntry = new StatsSet();
final String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
diaryEntry.set("date", date);
diaryEntry.set("action", template.getName() + " was defeated");
// Add to old list
_list.add(_diaryentry);
// Put new list into diary
_herodiary.put(charId, _list);
list.add(diaryEntry);
}
}
@@ -828,22 +809,17 @@ public class Hero
{
setDiaryData(charId, ACTION_CASTLE_TAKEN, castleId);
Castle castle = CastleManager.getInstance().getCastleById(castleId);
if ((castle != null) && _herodiary.containsKey(charId))
final Castle castle = CastleManager.getInstance().getCastleById(castleId);
final List<StatsSet> list = HERO_DIARY.get(charId);
if ((list != null) && (castle != null))
{
// Get Data
List<StatsSet> _list = _herodiary.get(charId);
// Clear old data
_herodiary.remove(charId);
// Prepare new data
StatsSet _diaryentry = new StatsSet();
String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
_diaryentry.set("date", date);
_diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
final StatsSet diaryEntry = new StatsSet();
final String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
diaryEntry.set("date", date);
diaryEntry.set("action", castle.getName() + " Castle was successfuly taken");
// Add to old list
_list.add(_diaryentry);
// Put new list into diary
_herodiary.put(charId, _list);
list.add(diaryEntry);
}
}
@@ -860,7 +836,7 @@ public class Hero
}
catch (SQLException e)
{
_log.log(Level.SEVERE, "SQL exception while saving DiaryData.", e);
_log.severe("SQL exception while saving DiaryData: " + e.getMessage());
}
}
@@ -871,7 +847,7 @@ public class Hero
*/
public void setHeroMessage(L2PcInstance player, String message)
{
_heroMessage.put(player.getObjectId(), message);
HERO_MESSAGE.put(player.getObjectId(), message);
}
/**
@@ -880,7 +856,7 @@ public class Hero
*/
public void saveHeroMessage(int charId)
{
if (_heroMessage.get(charId) == null)
if (HERO_MESSAGE.containsKey(charId))
{
return;
}
@@ -888,13 +864,13 @@ public class Hero
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("UPDATE heroes SET message=? WHERE charId=?;"))
{
statement.setString(1, _heroMessage.get(charId));
statement.setString(1, HERO_MESSAGE.get(charId));
statement.setInt(2, charId);
statement.execute();
}
catch (SQLException e)
{
_log.log(Level.SEVERE, "SQL exception while saving HeroMessage.", e);
_log.severe("SQL exception while saving HeroMessage:" + e.getMessage());
}
}
@@ -907,7 +883,7 @@ public class Hero
}
catch (SQLException e)
{
_log.log(Level.WARNING, "", e);
_log.warning("Heroes: " + e.getMessage());
}
}
@@ -917,10 +893,7 @@ public class Hero
*/
public void shutdown()
{
for (int charId : _heroMessage.keySet())
{
saveHeroMessage(charId);
}
HERO_MESSAGE.keySet().forEach(c -> saveHeroMessage(c));
}
/**
@@ -930,7 +903,7 @@ public class Hero
*/
public boolean isHero(int objectId)
{
return _heroes.containsKey(objectId) && _heroes.get(objectId).getBoolean(CLAIMED);
return HEROES.containsKey(objectId) && HEROES.get(objectId).getBoolean(CLAIMED);
}
/**
@@ -940,7 +913,7 @@ public class Hero
*/
public boolean isUnclaimedHero(int objectId)
{
return _heroes.containsKey(objectId) && !_heroes.get(objectId).getBoolean(CLAIMED);
return HEROES.containsKey(objectId) && !HEROES.get(objectId).getBoolean(CLAIMED);
}
/**
@@ -949,11 +922,11 @@ public class Hero
*/
public void claimHero(L2PcInstance player)
{
StatsSet hero = _heroes.get(player.getObjectId());
StatsSet hero = HEROES.get(player.getObjectId());
if (hero == null)
{
hero = new StatsSet();
_heroes.put(player.getObjectId(), hero);
HEROES.put(player.getObjectId(), hero);
}
hero.set(CLAIMED, true);
@@ -976,13 +949,18 @@ public class Hero
setHeroGained(player.getObjectId());
loadFights(player.getObjectId());
loadDiary(player.getObjectId());
_heroMessage.put(player.getObjectId(), "");
HERO_MESSAGE.put(player.getObjectId(), "");
updateHeroes(false);
}
public static Hero getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final Hero _instance = new Hero();
protected static final Hero INSTANCE = new Hero();
}
}