Loading data cleanup.

This commit is contained in:
MobiusDevelopment
2019-11-21 10:58:20 +00:00
parent 3c6964d12d
commit 1ff2b89dba
17 changed files with 244 additions and 498 deletions

View File

@@ -54,7 +54,7 @@ public class AccountManager
{ {
if (_mode.equals("1") || _mode.equals("2") || _mode.equals("3")) if (_mode.equals("1") || _mode.equals("2") || _mode.equals("3"))
{ {
while (_uname.length() == 0) while (_uname.isEmpty())
{ {
System.out.print("username: "); System.out.print("username: ");
_uname = _in.readLine(); _uname = _in.readLine();
@@ -62,7 +62,7 @@ public class AccountManager
} }
if (_mode.equals("1")) if (_mode.equals("1"))
{ {
while (_pass.length() == 0) while (_pass.isEmpty())
{ {
System.out.print("password: "); System.out.print("password: ");
_pass = _in.readLine(); _pass = _in.readLine();
@@ -70,7 +70,7 @@ public class AccountManager
} }
if (_mode.equals("1") || _mode.equals("2")) if (_mode.equals("1") || _mode.equals("2"))
{ {
while (_level.length() == 0) while (_level.isEmpty())
{ {
System.out.print("access level: "); System.out.print("access level: ");
_level = _in.readLine(); _level = _in.readLine();

View File

@@ -17,10 +17,9 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileInputStream;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -46,58 +45,42 @@ public class CharStatsTable
private CharStatsTable() private CharStatsTable()
{ {
BufferedReader lnr = null;
try try
{ {
File ModifierData = new File("data/char_stats.csv"); File modifierData = new File("data/char_stats.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(ModifierData))); if (modifierData.isFile() && modifierData.exists())
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(modifierData)));
String line = null;
while ((line = lnr.readLine()) != null)
{ {
continue; if (line.trim().isEmpty() || line.startsWith("#"))
{
continue;
}
StringTokenizer st = new StringTokenizer(line, ";");
StatModifiers modifier = new StatModifiers();
modifier.setClassid(Integer.parseInt(st.nextToken()));
modifier.setModstr(Integer.parseInt(st.nextToken()));
modifier.setModcon(Integer.parseInt(st.nextToken()));
modifier.setModdex(Integer.parseInt(st.nextToken()));
modifier.setModint(Integer.parseInt(st.nextToken()));
modifier.setModmen(Integer.parseInt(st.nextToken()));
modifier.setModwit(Integer.parseInt(st.nextToken()));
_modifiers.put(modifier.getClassid(), modifier);
} }
StatModifiers modif = parseList(line); lnr.close();
_modifiers.put(modif.getClassid(), modif); _log.config("Loaded " + _modifiers.size() + " character stat modifiers.");
}
else
{
_log.warning("char_stats.csv is missing in data folder.");
} }
_log.config("Loaded " + _modifiers.size() + " character stat modifiers.");
}
catch (FileNotFoundException e)
{
_log.warning("char_stats.csv is missing in data folder.");
} }
catch (Exception e) catch (Exception e)
{ {
_log.warning("Error while creating character modifier table " + e); _log.warning("Error while creating character modifier table " + e);
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private StatModifiers parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
StatModifiers modifier = new StatModifiers();
modifier.setClassid(Integer.parseInt(st.nextToken()));
modifier.setModstr(Integer.parseInt(st.nextToken()));
modifier.setModcon(Integer.parseInt(st.nextToken()));
modifier.setModdex(Integer.parseInt(st.nextToken()));
modifier.setModint(Integer.parseInt(st.nextToken()));
modifier.setModmen(Integer.parseInt(st.nextToken()));
modifier.setModwit(Integer.parseInt(st.nextToken()));
return modifier;
} }
public StatModifiers getTemplate(int id) public StatModifiers getTemplate(int id)

View File

@@ -17,10 +17,9 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileInputStream;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -46,83 +45,72 @@ public class CharTemplateTable
private CharTemplateTable() private CharTemplateTable()
{ {
BufferedReader lnr = null;
try try
{ {
File skillData = new File("data/char_templates.csv"); File charTemplateData = new File("data/char_templates.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData))); if (charTemplateData.isFile() && charTemplateData.exists())
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(charTemplateData)));
String line = null;
while ((line = lnr.readLine()) != null)
{ {
continue; if (line.trim().isEmpty() || line.startsWith("#"))
{
continue;
}
L2CharTemplate ct = new L2CharTemplate();
StringTokenizer st = new StringTokenizer(line, ";");
ct.setClassId(Integer.parseInt(st.nextToken()));
ct.setClassName(st.nextToken());
ct.setRaceId(Integer.parseInt(st.nextToken()));
ct.setStr(Integer.parseInt(st.nextToken()));
ct.setCon(Integer.parseInt(st.nextToken()));
ct.setDex(Integer.parseInt(st.nextToken()));
ct.setInt(Integer.parseInt(st.nextToken()));
ct.setWit(Integer.parseInt(st.nextToken()));
ct.setMen(Integer.parseInt(st.nextToken()));
ct.setHp(Integer.parseInt(st.nextToken()));
ct.setMp(Integer.parseInt(st.nextToken()));
ct.setPatk(Integer.parseInt(st.nextToken()));
ct.setPdef(Integer.parseInt(st.nextToken()));
ct.setMatk(Integer.parseInt(st.nextToken()));
ct.setMdef(Integer.parseInt(st.nextToken()));
ct.setPspd(Integer.parseInt(st.nextToken()));
ct.setMspd(Integer.parseInt(st.nextToken()));
ct.setAcc(Integer.parseInt(st.nextToken()));
ct.setCrit(Integer.parseInt(st.nextToken()));
ct.setEvas(Integer.parseInt(st.nextToken()));
ct.setMoveSpd(Integer.parseInt(st.nextToken()));
ct.setLoad(Integer.parseInt(st.nextToken()));
ct.setX(Integer.parseInt(st.nextToken()));
ct.setY(Integer.parseInt(st.nextToken()));
ct.setZ(Integer.parseInt(st.nextToken()));
ct.setCanCraft(Integer.parseInt(st.nextToken()));
ct.setMUnk1(Double.parseDouble(st.nextToken()));
ct.setMUnk2(Double.parseDouble(st.nextToken()));
ct.setMColR(Double.parseDouble(st.nextToken()));
ct.setMColH(Double.parseDouble(st.nextToken()));
ct.setFUnk1(Double.parseDouble(st.nextToken()));
ct.setFUnk2(Double.parseDouble(st.nextToken()));
ct.setFColR(Double.parseDouble(st.nextToken()));
ct.setFColH(Double.parseDouble(st.nextToken()));
while (st.hasMoreTokens())
{
ct.addItem(Integer.parseInt(st.nextToken()));
}
_templates.put(ct.getClassId(), ct);
} }
L2CharTemplate ct = new L2CharTemplate(); lnr.close();
StringTokenizer st = new StringTokenizer(line, ";"); _log.config("Loaded " + _templates.size() + " char templates.");
ct.setClassId(Integer.parseInt(st.nextToken())); }
ct.setClassName(st.nextToken()); else
ct.setRaceId(Integer.parseInt(st.nextToken())); {
ct.setStr(Integer.parseInt(st.nextToken())); _log.warning("char_templates.csv is missing in data folder, char creation will fail.");
ct.setCon(Integer.parseInt(st.nextToken()));
ct.setDex(Integer.parseInt(st.nextToken()));
ct.setInt(Integer.parseInt(st.nextToken()));
ct.setWit(Integer.parseInt(st.nextToken()));
ct.setMen(Integer.parseInt(st.nextToken()));
ct.setHp(Integer.parseInt(st.nextToken()));
ct.setMp(Integer.parseInt(st.nextToken()));
ct.setPatk(Integer.parseInt(st.nextToken()));
ct.setPdef(Integer.parseInt(st.nextToken()));
ct.setMatk(Integer.parseInt(st.nextToken()));
ct.setMdef(Integer.parseInt(st.nextToken()));
ct.setPspd(Integer.parseInt(st.nextToken()));
ct.setMspd(Integer.parseInt(st.nextToken()));
ct.setAcc(Integer.parseInt(st.nextToken()));
ct.setCrit(Integer.parseInt(st.nextToken()));
ct.setEvas(Integer.parseInt(st.nextToken()));
ct.setMoveSpd(Integer.parseInt(st.nextToken()));
ct.setLoad(Integer.parseInt(st.nextToken()));
ct.setX(Integer.parseInt(st.nextToken()));
ct.setY(Integer.parseInt(st.nextToken()));
ct.setZ(Integer.parseInt(st.nextToken()));
ct.setCanCraft(Integer.parseInt(st.nextToken()));
ct.setMUnk1(Double.parseDouble(st.nextToken()));
ct.setMUnk2(Double.parseDouble(st.nextToken()));
ct.setMColR(Double.parseDouble(st.nextToken()));
ct.setMColH(Double.parseDouble(st.nextToken()));
ct.setFUnk1(Double.parseDouble(st.nextToken()));
ct.setFUnk2(Double.parseDouble(st.nextToken()));
ct.setFColR(Double.parseDouble(st.nextToken()));
ct.setFColH(Double.parseDouble(st.nextToken()));
while (st.hasMoreTokens())
{
ct.addItem(Integer.parseInt(st.nextToken()));
}
_templates.put(ct.getClassId(), ct);
} }
_log.config("Loaded " + _templates.size() + " char templates.");
}
catch (FileNotFoundException e)
{
_log.warning("char_templates.csv is missing in data folder, char creation will fail.");
} }
catch (Exception e) catch (Exception e)
{ {
_log.warning("Error while loading char templates " + e); _log.warning("Error while loading char templates " + e);
e.printStackTrace();
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
} }
} }

View File

@@ -17,11 +17,10 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileInputStream;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@@ -71,17 +70,16 @@ public class ClanTable
private Clan restoreClan(File file) private Clan restoreClan(File file)
{ {
BufferedReader lnr = null;
Clan clan = null; Clan clan = null;
try try
{ {
lnr = new LineNumberReader(new BufferedReader(new FileReader(file))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(file)));
((LineNumberReader) lnr).readLine(); lnr.readLine();
clan = parseClanData(((LineNumberReader) lnr).readLine()); clan = parseClanData(lnr.readLine());
((LineNumberReader) lnr).readLine(); lnr.readLine();
String line = null; String line = null;
boolean first = true; boolean first = true;
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
ClanMember member = parseMembers(line); ClanMember member = parseMembers(line);
if (first) if (first)
@@ -92,24 +90,12 @@ public class ClanTable
} }
clan.addClanMember(member); clan.addClanMember(member);
} }
lnr.close();
} }
catch (IOException e) catch (Exception e)
{ {
_log.warning("Could not read clan file:" + e.getMessage()); _log.warning("Could not read clan file:" + e.getMessage());
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
return clan; return clan;
} }

View File

@@ -43,7 +43,7 @@ public class ExperienceTable
String line = null; String line = null;
while ((line = lnr.readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }

View File

@@ -219,7 +219,7 @@ public class ItemTable
{ {
try try
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
@@ -334,7 +334,8 @@ public class ItemTable
} }
catch (Exception e) catch (Exception e)
{ {
_log.warning("Data error on etc item:" + result + " " + e); _log.warning("Data error on etc item:" + result + " line: " + line);
e.printStackTrace();
} }
return result; return result;
} }

View File

@@ -17,10 +17,10 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -47,21 +47,29 @@ public class LevelUpData
private LevelUpData() private LevelUpData()
{ {
BufferedReader lnr = null;
try try
{ {
File spawnDataFile = new File("data/lvlupgain.csv"); File spawnDataFile = new File("data/lvlupgain.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(spawnDataFile))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(spawnDataFile)));
String line = null; String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
LvlupData lvlupData = parseList(line); StringTokenizer st = new StringTokenizer(line, ";");
LvlupData lvlupData = new LvlupData();
lvlupData.setClassid(Integer.parseInt(st.nextToken()));
lvlupData.setDefaulthp(Double.parseDouble(st.nextToken()));
lvlupData.setDefaulthpadd(Double.parseDouble(st.nextToken()));
lvlupData.setDefaulthpbonus(Double.parseDouble(st.nextToken()));
lvlupData.setDefaultmp(Double.parseDouble(st.nextToken()));
lvlupData.setDefaultmpadd(Double.parseDouble(st.nextToken()));
lvlupData.setDefaultmpbonus(Double.parseDouble(st.nextToken()));
_lvltable.put(lvlupData.getClassid(), lvlupData); _lvltable.put(lvlupData.getClassid(), lvlupData);
} }
lnr.close();
_log.config("Loaded " + _lvltable.size() + " Lvl up data templates."); _log.config("Loaded " + _lvltable.size() + " Lvl up data templates.");
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
@@ -72,33 +80,6 @@ public class LevelUpData
{ {
_log.warning("Error while creating npc data table " + e); _log.warning("Error while creating npc data table " + e);
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private LvlupData parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
LvlupData lvlDat = new LvlupData();
lvlDat.setClassid(Integer.parseInt(st.nextToken()));
lvlDat.setDefaulthp(Double.parseDouble(st.nextToken()));
lvlDat.setDefaulthpadd(Double.parseDouble(st.nextToken()));
lvlDat.setDefaulthpbonus(Double.parseDouble(st.nextToken()));
lvlDat.setDefaultmp(Double.parseDouble(st.nextToken()));
lvlDat.setDefaultmpadd(Double.parseDouble(st.nextToken()));
lvlDat.setDefaultmpbonus(Double.parseDouble(st.nextToken()));
return lvlDat;
} }
public LvlupData getTemplate(int classId) public LvlupData getTemplate(int classId)

View File

@@ -17,11 +17,9 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileInputStream;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.IOException;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -49,15 +47,14 @@ public class MapRegionTable
super(); super();
int count = 0; int count = 0;
int count2 = 0; int count2 = 0;
LineNumberReader lnr = null;
try try
{ {
File regionDataFile = new File("data/mapregion.csv"); File regionDataFile = new File("data/mapregion.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(regionDataFile))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(regionDataFile)));
String line = null; String line = null;
while ((line = lnr.readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
@@ -68,55 +65,12 @@ public class MapRegionTable
} }
++count; ++count;
} }
try
{
_log.fine("Loaded " + count2 + " map regions.");
lnr.close();
return;
}
catch (FileNotFoundException e)
{
_log.warning("mapregion.csv is missing in data folder.");
try
{
}
catch (Exception e1)
{
return;
}
_log.fine("Loaded " + count2 + " map regions.");
lnr.close();
return;
}
catch (Exception e)
{
_log.warning("Rrror while creating map region data: " + e);
try
{
}
catch (Exception e1)
{
return;
}
_log.fine("Loaded " + count2 + " map regions.");
lnr.close();
return;
}
}
catch (Throwable throwable)
{
_log.fine("Loaded " + count2 + " map regions."); _log.fine("Loaded " + count2 + " map regions.");
try lnr.close();
{ }
if (lnr != null) catch (Exception e)
{ {
lnr.close(); _log.fine("Error loading map regions. " + e);
}
}
catch (IOException e)
{
}
} }
} }
@@ -127,7 +81,7 @@ public class MapRegionTable
return _regions[tileX][tileY]; return _regions[tileX][tileY];
} }
public String getClosestTownCords(Creature activeChar) public int[] getClosestTownCords(Creature activeChar)
{ {
int[][] pos = new int[13][3]; int[][] pos = new int[13][3];
pos[0][0] = -84176; pos[0][0] = -84176;
@@ -170,7 +124,12 @@ public class MapRegionTable
pos[12][1] = 148497; pos[12][1] = 148497;
pos[12][2] = -3404; pos[12][2] = -3404;
int closest = getMapRegion(activeChar.getX(), activeChar.getY()); int closest = getMapRegion(activeChar.getX(), activeChar.getY());
String ClosestTownCords = pos[closest][0] + "!" + pos[closest][1] + "!" + pos[closest][2]; int[] ClosestTownCords =
{
pos[closest][0],
pos[closest][1],
pos[closest][2]
};
return ClosestTownCords; return ClosestTownCords;
} }
} }

View File

@@ -17,10 +17,10 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -60,21 +60,21 @@ public class NpcTable
private void parseData() private void parseData()
{ {
BufferedReader lnr = null;
try try
{ {
File skillData = new File("data/npc.csv"); File npcData = new File("data/npc.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(npcData)));
String line = null; String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
L2Npc npc = parseList(line); L2Npc npc = parseList(line);
_npcs.put(npc.getNpcId(), npc); _npcs.put(npc.getNpcId(), npc);
} }
lnr.close();
_log.config("Loaded " + _npcs.size() + " NPC templates."); _log.config("Loaded " + _npcs.size() + " NPC templates.");
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
@@ -87,19 +87,6 @@ public class NpcTable
_initialized = false; _initialized = false;
_log.warning("Error while creating npc table " + e); _log.warning("Error while creating npc table " + e);
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
} }
private L2Npc parseList(String line) private L2Npc parseList(String line)
@@ -121,15 +108,14 @@ public class NpcTable
private void parseAdditionalData() private void parseAdditionalData()
{ {
BufferedReader lnr = null;
try try
{ {
File npcDataFile = new File("data/npc2.csv"); File npcData2 = new File("data/npc2.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(npcDataFile))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(npcData2)));
String line = null; String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
@@ -139,9 +125,10 @@ public class NpcTable
} }
catch (Exception e) catch (Exception e)
{ {
_log.warning("Parsing error in npc2.csv, line " + ((LineNumberReader) lnr).getLineNumber() + " / " + e.toString()); _log.warning("Parsing error in npc2.csv, line " + lnr.getLineNumber() + " / " + e.toString());
} }
} }
lnr.close();
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
@@ -151,19 +138,6 @@ public class NpcTable
{ {
_log.warning("Error while creating npc data table " + e); _log.warning("Error while creating npc data table " + e);
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
} }
private void parseAdditionalDataLine(String line) private void parseAdditionalDataLine(String line)
@@ -201,16 +175,15 @@ public class NpcTable
private void parseDropData() private void parseDropData()
{ {
BufferedReader lnr = null;
try try
{ {
File dropDataFile = new File("data/droplist.csv"); File dropData = new File("data/droplist.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(dropDataFile))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(dropData)));
String line = null; String line = null;
int n = 0; int n = 0;
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
@@ -221,10 +194,11 @@ public class NpcTable
} }
catch (Exception e) catch (Exception e)
{ {
_log.warning("Parsing error in droplist.csv, line " + ((LineNumberReader) lnr).getLineNumber() + " / " + e.toString()); _log.warning("Parsing error in droplist.csv, line " + lnr.getLineNumber() + " / " + e.toString());
} }
} }
_log.config("Loaded " + n + " drop data templates."); _log.config("Loaded " + n + " drop data templates.");
lnr.close();
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
@@ -234,19 +208,6 @@ public class NpcTable
{ {
_log.warning("Error while creating drop data table " + e); _log.warning("Error while creating drop data table " + e);
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
} }
private void parseDropLine(String line) private void parseDropLine(String line)

View File

@@ -17,11 +17,9 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileInputStream;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.IOException;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -49,85 +47,39 @@ public class PriceListTable
public void loadPriceList() public void loadPriceList()
{ {
File file = new File("data/pricelist.csv");
if (file.exists())
{
try
{
readFromDisk(file);
}
catch (IOException e)
{
}
}
else
{
_log.config("data/pricelist.csv is missing!");
}
}
private void readFromDisk(File file) throws IOException
{
BufferedReader lnr = null;
int i = 0;
String line = null;
lnr = new LineNumberReader(new FileReader(file));
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if (line.startsWith("#"))
{
continue;
}
StringTokenizer st = new StringTokenizer(line, ";");
int itemId = Integer.parseInt(st.nextToken().toString());
int price = Integer.parseInt(st.nextToken().toString());
L2Item temp = ItemTable.getInstance().getTemplate(itemId);
temp.setItemId(itemId);
temp.setReferencePrice(price);
++i;
}
_log.config("Loaded " + i + " prices.");
try try
{ {
lnr.close(); File file = new File("data/pricelist.csv");
return; if (file.isFile() && file.exists())
}
catch (FileNotFoundException e)
{
try
{ {
int i = 0;
String line = null;
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(file)));
while ((line = lnr.readLine()) != null)
{
if (line.startsWith("#"))
{
continue;
}
StringTokenizer st = new StringTokenizer(line, ";");
int itemId = Integer.parseInt(st.nextToken().toString());
int price = Integer.parseInt(st.nextToken().toString());
L2Item temp = ItemTable.getInstance().getTemplate(itemId);
temp.setItemId(itemId);
temp.setReferencePrice(price);
++i;
}
_log.config("Loaded " + i + " prices.");
lnr.close(); lnr.close();
return;
} }
catch (IOException e1) else
{ {
try _log.config("data/pricelist.csv is missing!");
{
e1.printStackTrace();
}
catch (Throwable throwable)
{
try
{
lnr.close();
throw throwable;
}
catch (Exception e2)
{
// empty catch block
}
throw throwable;
}
try
{
lnr.close();
return;
}
catch (Exception e2)
{
return;
}
} }
} }
catch (Exception e)
{
_log.warning("Error while loading price lists: " + e);
}
} }
} }

View File

@@ -19,8 +19,10 @@ package org.l2jmobius.gameserver.data;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -47,15 +49,14 @@ public class SkillTable
private SkillTable() private SkillTable()
{ {
BufferedReader lnr = null;
try try
{ {
File skillData = new File("data/skills.csv"); File skillData = new File("data/skills.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(skillData)));
String line = null; String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
@@ -65,14 +66,15 @@ public class SkillTable
skillData = new File("data/skills2.csv"); skillData = new File("data/skills2.csv");
lnr.close(); lnr.close();
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData))); lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData)));
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
parseList2(line); parseList2(line);
} }
lnr.close();
_log.config("Loaded " + _skills.size() + " skills."); _log.config("Loaded " + _skills.size() + " skills.");
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
@@ -85,19 +87,6 @@ public class SkillTable
_initialized = false; _initialized = false;
_log.warning("Error while creating skill table: " + e.toString()); _log.warning("Error while creating skill table: " + e.toString());
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
} }
public boolean isInitialized() public boolean isInitialized()

View File

@@ -17,10 +17,10 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -170,20 +170,19 @@ public class SkillTreeTable
private void readFile(File skillData, int classId, int parentClassId) private void readFile(File skillData, int classId, int parentClassId)
{ {
BufferedReader lnr = null;
String line = null; String line = null;
try try
{ {
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(skillData)));
List<SkillLearn> list = new ArrayList<>(); List<SkillLearn> list = new ArrayList<>();
if (parentClassId != -1) if (parentClassId != -1)
{ {
List<SkillLearn> parentList = _skillTrees.get(parentClassId); List<SkillLearn> parentList = _skillTrees.get(parentClassId);
list.addAll(parentList); list.addAll(parentList);
} }
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
@@ -191,6 +190,7 @@ public class SkillTreeTable
list.add(skill); list.add(skill);
} }
_skillTrees.put(classId, list); _skillTrees.put(classId, list);
lnr.close();
_log.config("Skill tree for class " + classId + " has " + list.size() + " skills."); _log.config("Skill tree for class " + classId + " has " + list.size() + " skills.");
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
@@ -200,20 +200,6 @@ public class SkillTreeTable
catch (Exception e) catch (Exception e)
{ {
_log.warning("Error while creating skill tree for classId " + classId + " " + line + " " + e); _log.warning("Error while creating skill tree for classId " + classId + " " + line + " " + e);
e.printStackTrace();
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
} }
} }

View File

@@ -17,10 +17,10 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -49,17 +49,16 @@ public class SpawnTable
private SpawnTable() private SpawnTable()
{ {
BufferedReader lnr = null;
try try
{ {
File spawnDataFile = new File("data/spawnlist.csv"); File spawnDataFile = new File("data/spawnlist.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(spawnDataFile))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(spawnDataFile)));
String line = null; String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
try try
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
@@ -76,6 +75,7 @@ public class SpawnTable
_log.warning("Spawn could not be initialized: " + e1); _log.warning("Spawn could not be initialized: " + e1);
} }
} }
lnr.close();
_log.config("Created " + _spawntable.size() + " spawn handlers."); _log.config("Created " + _spawntable.size() + " spawn handlers.");
_log.fine("Spawning completed, total number of NPCs in the world: " + _npcSpawnCount); _log.fine("Spawning completed, total number of NPCs in the world: " + _npcSpawnCount);
} }
@@ -87,19 +87,6 @@ public class SpawnTable
{ {
_log.warning("error while creating spawn list " + e); _log.warning("error while creating spawn list " + e);
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
} }
private Spawn parseList(String line) throws SecurityException, ClassNotFoundException private Spawn parseList(String line) throws SecurityException, ClassNotFoundException

View File

@@ -17,10 +17,9 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileInputStream;
import java.io.FileReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -46,56 +45,40 @@ public class TeleportLocationTable
private TeleportLocationTable() private TeleportLocationTable()
{ {
BufferedReader lnr = null;
try try
{ {
File teleData = new File("data/teleport.csv"); File teleData = new File("data/teleport.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(teleData))); if (teleData.isFile() && teleData.exists())
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(teleData)));
String line = null;
while ((line = lnr.readLine()) != null)
{ {
continue; if (line.trim().isEmpty() || line.startsWith("#"))
{
continue;
}
StringTokenizer st = new StringTokenizer(line, ";");
TeleportLocation teleport = new TeleportLocation();
teleport.setTeleId(Integer.parseInt(st.nextToken()));
teleport.setLocX(Integer.parseInt(st.nextToken()));
teleport.setLocY(Integer.parseInt(st.nextToken()));
teleport.setLocZ(Integer.parseInt(st.nextToken()));
teleport.setPrice(Integer.parseInt(st.nextToken()));
_teleports.put(teleport.getTeleId(), teleport);
} }
TeleportLocation tele = parseList(line); lnr.close();
_teleports.put(tele.getTeleId(), tele); _log.config("Loaded " + _teleports.size() + " Teleport templates.");
}
else
{
_log.warning("teleport.csv is missing in data folder.");
} }
_log.config("Loaded " + _teleports.size() + " Teleport templates.");
}
catch (FileNotFoundException e)
{
_log.warning("teleport.csv is missing in data folder.");
} }
catch (Exception e) catch (Exception e)
{ {
_log.warning("Error while creating teleport table " + e); _log.warning("Error while creating teleport table " + e);
} }
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private TeleportLocation parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
TeleportLocation teleport = new TeleportLocation();
teleport.setTeleId(Integer.parseInt(st.nextToken()));
teleport.setLocX(Integer.parseInt(st.nextToken()));
teleport.setLocY(Integer.parseInt(st.nextToken()));
teleport.setLocZ(Integer.parseInt(st.nextToken()));
teleport.setPrice(Integer.parseInt(st.nextToken()));
return teleport;
} }
public TeleportLocation getTemplate(int id) public TeleportLocation getTemplate(int id)

View File

@@ -17,9 +17,10 @@
*/ */
package org.l2jmobius.gameserver.data; package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -47,31 +48,30 @@ public class TradeController
private TradeController() private TradeController()
{ {
String line = null; String line = null;
LineNumberReader lnr = null;
int dummyItemCount = 0; int dummyItemCount = 0;
try try
{ {
File buylistData = new File("data/buylists.csv"); File buylistData = new File("data/buylists.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(buylistData))); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(buylistData)));
while ((line = lnr.readLine()) != null) while ((line = lnr.readLine()) != null)
{ {
if ((line.trim().length() == 0) || line.startsWith("#")) if (line.trim().isEmpty() || line.startsWith("#"))
{ {
continue; continue;
} }
dummyItemCount += parseList(line); dummyItemCount += parseList(line);
} }
lnr.close();
_log.fine("Created " + dummyItemCount + " Dummy-Items for buylists."); _log.fine("Created " + dummyItemCount + " Dummy-Items for buylists.");
_log.config("Loaded " + _lists.size() + " buylists."); _log.config("Loaded " + _lists.size() + " buylists.");
} }
catch (FileNotFoundException e)
{
_log.warning("No buylists were found in data folder.");
}
catch (Exception e) catch (Exception e)
{ {
if (lnr != null) _log.warning("Error while creating buylists: " + e);
{
_log.warning("Error while creating trade controller in linenr: " + lnr.getLineNumber());
e.printStackTrace();
}
_log.warning("No buylists were found in data folder.");
} }
} }

View File

@@ -40,12 +40,7 @@ public class ScrollOfEscape implements IItemHandler
@Override @Override
public int useItem(PlayerInstance activeChar, ItemInstance item) public int useItem(PlayerInstance activeChar, ItemInstance item)
{ {
String townCordsString = MapRegionTable.getInstance().getClosestTownCords(activeChar); int[] townCords = MapRegionTable.getInstance().getClosestTownCords(activeChar);
String[] temp = null;
temp = townCordsString.split("!");
int townX = Integer.parseInt(temp[0]);
int townY = Integer.parseInt(temp[1]);
int townZ = Integer.parseInt(temp[2]);
activeChar.setTarget(activeChar); activeChar.setTarget(activeChar);
Skill skill = SkillTable.getInstance().getInfo(1050, 1); Skill skill = SkillTable.getInstance().getInfo(1050, 1);
MagicSkillUser msk = new MagicSkillUser(activeChar, 1050, 1, 20000, 0); MagicSkillUser msk = new MagicSkillUser(activeChar, 1050, 1, 20000, 0);
@@ -71,12 +66,12 @@ public class ScrollOfEscape implements IItemHandler
activeChar.sendPacket(af); activeChar.sendPacket(af);
World.getInstance().removeVisibleObject(activeChar); World.getInstance().removeVisibleObject(activeChar);
activeChar.removeAllKnownObjects(); activeChar.removeAllKnownObjects();
TeleportToLocation teleport = new TeleportToLocation(activeChar, townX, townY, townZ); TeleportToLocation teleport = new TeleportToLocation(activeChar, townCords[0], townCords[1], townCords[2]);
activeChar.sendPacket(teleport); activeChar.sendPacket(teleport);
activeChar.broadcastPacket(teleport); activeChar.broadcastPacket(teleport);
activeChar.setX(townX); activeChar.setX(townCords[0]);
activeChar.setY(townY); activeChar.setY(townCords[1]);
activeChar.setZ(townZ); activeChar.setZ(townCords[2]);
try try
{ {
Thread.sleep(2000L); Thread.sleep(2000L);

View File

@@ -39,24 +39,19 @@ public class RequestRestartPoint extends ClientBasePacket
super(decrypt); super(decrypt);
Connection con = client.getConnection(); Connection con = client.getConnection();
PlayerInstance activeChar = client.getActiveChar(); PlayerInstance activeChar = client.getActiveChar();
String townCordsString = MapRegionTable.getInstance().getClosestTownCords(activeChar); int[] townCords = MapRegionTable.getInstance().getClosestTownCords(activeChar);
String[] temp = null;
temp = townCordsString.split("!");
int townX = Integer.parseInt(temp[0]);
int townY = Integer.parseInt(temp[1]);
int townZ = Integer.parseInt(temp[2]);
StopMove stopMove = new StopMove(activeChar); StopMove stopMove = new StopMove(activeChar);
con.sendPacket(stopMove); con.sendPacket(stopMove);
ActionFailed actionFailed = new ActionFailed(); ActionFailed actionFailed = new ActionFailed();
con.sendPacket(actionFailed); con.sendPacket(actionFailed);
activeChar.broadcastPacket(stopMove); activeChar.broadcastPacket(stopMove);
TeleportToLocation teleport = new TeleportToLocation(activeChar, townX, townY, townZ); TeleportToLocation teleport = new TeleportToLocation(activeChar, townCords[0], townCords[1], townCords[2]);
activeChar.sendPacket(teleport); activeChar.sendPacket(teleport);
World.getInstance().removeVisibleObject(activeChar); World.getInstance().removeVisibleObject(activeChar);
activeChar.removeAllKnownObjects(); activeChar.removeAllKnownObjects();
activeChar.setX(townX); activeChar.setX(townCords[0]);
activeChar.setY(townY); activeChar.setY(townCords[1]);
activeChar.setZ(townZ); activeChar.setZ(townCords[2]);
activeChar.setCurrentHp(0.6 * activeChar.getMaxHp()); activeChar.setCurrentHp(0.6 * activeChar.getMaxHp());
activeChar.setCurrentMp(0.6 * activeChar.getMaxMp()); activeChar.setCurrentMp(0.6 * activeChar.getMaxMp());
Revive revive = new Revive(activeChar); Revive revive = new Revive(activeChar);