Code review Part 2.

This commit is contained in:
MobiusDevelopment
2019-12-18 11:25:03 +00:00
parent b7fef9acf5
commit 6954f58f5e
739 changed files with 6985 additions and 8820 deletions

View File

@@ -43,7 +43,6 @@ public class Config
private static final String NPC_CONFIG_FILE = "./config/npc.ini";
// Game
public static String _ip;
public static int SERVER_PORT;
public static String SERVER_HOST_NAME;
public static int CLIENT_PROTOCOL_VERSION;

View File

@@ -20,6 +20,7 @@ package org.l2jmobius.gameserver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.StringTokenizer;
import java.util.logging.Logger;
@@ -441,7 +442,7 @@ public class AdminCommands extends Thread
{
final PlayerInstance activeChar = client.getActiveChar();
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Server Status</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Server Status</title>");
replyMSG.append("<body>");
replyMSG.append("<table>");
replyMSG.append("<tr><td>Players Online: " + World.getInstance().getAllPlayers().size() + "</td></tr>");
@@ -492,7 +493,7 @@ public class AdminCommands extends Thread
activeChar.sendPacket(il);
activeChar.sendMessage("You have spawned " + num + " item(s) number " + id + " in your inventory.");
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Item Creation Complete</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Item Creation Complete</title>");
replyMSG.append("<body>");
replyMSG.append("<center><button value=\"Back\" action=\"bypass -h admin_show\" width=40 height=15></center>");
replyMSG.append("</body></html>");
@@ -505,23 +506,23 @@ public class AdminCommands extends Thread
final PlayerInstance activeChar = client.getActiveChar();
final Collection<PlayerInstance> allWorldPlayers = World.getInstance().getAllPlayers();
final PlayerInstance[] players = allWorldPlayers.toArray(new PlayerInstance[allWorldPlayers.size()]);
final int MaxCharactersPerPage = 20;
int MaxPages = players.length / MaxCharactersPerPage;
final int modulus = players.length % MaxCharactersPerPage;
final int maxCharactersPerPage = 20;
int maxPages = players.length / maxCharactersPerPage;
final int modulus = players.length % maxCharactersPerPage;
if (modulus != 0)
{
++MaxPages;
++maxPages;
}
if (page > MaxPages)
if (page > maxPages)
{
page = MaxPages;
page = maxPages;
}
final int CharactersStart = MaxCharactersPerPage * page;
final int CharactersStart = maxCharactersPerPage * page;
final int CharactersEnd = players.length - CharactersStart;
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Characters List</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Characters List</title>");
replyMSG.append("<body>");
for (int x = 0; x < MaxPages; ++x)
for (int x = 0; x < maxPages; ++x)
{
replyMSG.append("<a action=\"bypass -h admin_show_characters " + x + "\">Page" + x + 1 + "</a>\t");
}
@@ -543,12 +544,12 @@ public class AdminCommands extends Thread
activeChar.sendPacket(adminReply);
}
private void showCharacterList(ClientThread client, String CharName)
private void showCharacterList(ClientThread client, String charName)
{
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(CharName);
final PlayerInstance player = World.getInstance().getPlayer(charName);
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Character Information</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Character Information</title>");
replyMSG.append("<body>");
replyMSG.append("<br>");
replyMSG.append("<center>" + player.getName() + "</center><p>");
@@ -609,7 +610,7 @@ public class AdminCommands extends Thread
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(_characterToManipulate);
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Add Exp-Sp to " + player.getName() + "</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Add Exp-Sp to " + player.getName() + "</title>");
replyMSG.append("<body>");
replyMSG.append("<br>");
replyMSG.append("<center>Lv: " + player.getLevel() + " " + CharTemplateTable.getInstance().getTemplate(player.getClassId()).getClassName() + "<p>");
@@ -628,11 +629,11 @@ public class AdminCommands extends Thread
activeChar.sendPacket(adminReply);
}
private void adminAddExpSp(ClientThread client, String ExpSp)
private void adminAddExpSp(ClientThread client, String expSp)
{
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(_characterToManipulate);
final StringTokenizer st = new StringTokenizer(ExpSp);
final StringTokenizer st = new StringTokenizer(expSp);
if (st.countTokens() != 2)
{
addExpSp(client);
@@ -707,7 +708,7 @@ public class AdminCommands extends Thread
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(_characterToManipulate);
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Editing character " + player.getName() + "</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Editing character " + player.getName() + "</title>");
replyMSG.append("<body>");
replyMSG.append("<br><center>Caution ! Dont forget that modifying players stats can ruin the game...</center><br>");
replyMSG.append("Note: you must type all values to confirm modifications.</center><br>");
@@ -775,27 +776,27 @@ public class AdminCommands extends Thread
showMainPage(client);
}
private void findCharacter(ClientThread client, String CharacterToFind)
private void findCharacter(ClientThread client, String characterToFind)
{
final PlayerInstance activeChar = client.getActiveChar();
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
int CharactersFound = 0;
final StringBuffer replyMSG = new StringBuffer("<html><title>Character Search</title>");
int charactersFound = 0;
final StringBuilder replyMSG = new StringBuilder("<html><title>Character Search</title>");
replyMSG.append("<body>");
replyMSG.append("<br>");
replyMSG.append("<table>");
replyMSG.append("<tr><td>Name</td><td>Class</td><td>Level</td></tr>");
for (PlayerInstance player : World.getInstance().getAllPlayers())
{
if (!player.getName().startsWith(CharacterToFind))
if (!player.getName().startsWith(characterToFind))
{
continue;
}
++CharactersFound;
++charactersFound;
replyMSG.append("<tr><td><a action=\"bypass -h admin_character_list " + player.getName() + "\">" + player.getName() + "</a>" + "</td><td>" + CharTemplateTable.getInstance().getTemplate(player.getClassId()).getClassName() + "</td><td>" + player.getLevel() + "</td></tr>");
}
replyMSG.append("</table>");
if (CharactersFound == 0)
if (charactersFound == 0)
{
replyMSG.append("<br>Your search did not find any characters. Please try again:");
replyMSG.append("<edit var=\"character_name\" width=110>");
@@ -804,12 +805,12 @@ public class AdminCommands extends Thread
}
else
{
replyMSG.append("<br>Found " + CharactersFound + " character");
if (CharactersFound == 1)
replyMSG.append("<br>Found " + charactersFound + " character");
if (charactersFound == 1)
{
replyMSG.append(".");
}
else if (CharactersFound > 1)
else if (charactersFound > 1)
{
replyMSG.append("s.");
}
@@ -826,7 +827,7 @@ public class AdminCommands extends Thread
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(_characterToManipulate);
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Teleport Character</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Teleport Character</title>");
replyMSG.append("<body>");
replyMSG.append("The character you will teleport is " + player.getName() + ".");
replyMSG.append("<br>");
@@ -844,7 +845,7 @@ public class AdminCommands extends Thread
activeChar.sendPacket(adminReply);
}
private void teleportCharacter(ClientThread client, String Cords)
private void teleportCharacter(ClientThread client, String coords)
{
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(_characterToManipulate);
@@ -854,7 +855,7 @@ public class AdminCommands extends Thread
}
else
{
final StringTokenizer st = new StringTokenizer(Cords);
final StringTokenizer st = new StringTokenizer(coords);
final String x1 = st.nextToken();
final int x = Integer.parseInt(x1);
final String y1 = st.nextToken();
@@ -888,7 +889,7 @@ public class AdminCommands extends Thread
{
final PlayerInstance activeChar = client.getActiveChar();
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Custom Spawn Menu</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Custom Spawn Menu</title>");
replyMSG.append("<body><br>Enter target player's name below.<br>You may leave the field blank for self-spawn.<br><br>");
replyMSG.append("<center><edit var=\"targetname\" width=160></center><br><br>");
replyMSG.append("<center><button value=\"Spawn on self\" action=\"bypass -h admin_spawn_confirm " + monsterId + " " + activeChar.getName() + "\" width=160 height=15></center><br>");
@@ -897,10 +898,10 @@ public class AdminCommands extends Thread
activeChar.sendPacket(adminReply);
}
private void spawnMonster(ClientThread client, String monsterId, String CharName)
private void spawnMonster(ClientThread client, String monsterId, String charName)
{
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance targetPlayer = World.getInstance().getPlayer(CharName);
final PlayerInstance targetPlayer = World.getInstance().getPlayer(charName);
final int monsterTemplate = Integer.parseInt(monsterId);
final Npc template1 = NpcTable.getInstance().getTemplate(monsterTemplate);
if (template1 == null)
@@ -931,14 +932,13 @@ public class AdminCommands extends Thread
private int disconnectAllCharacters()
{
final LeaveWorld leaveWorld = new LeaveWorld();
for (PlayerInstance player : World.getInstance().getAllPlayers())
{
final LeaveWorld ql = new LeaveWorld();
player.sendPacket(ql);
player.sendPacket(leaveWorld);
try
{
player.getNetConnection().close();
continue;
}
catch (IOException e)
{
@@ -952,8 +952,8 @@ public class AdminCommands extends Thread
{
secondsShut = seconds;
clientShut = client;
final AdminCommands ShutDownThread = new AdminCommands();
ShutDownThread.start();
final AdminCommands shutDownThread = new AdminCommands();
shutDownThread.start();
}
@Override
@@ -963,7 +963,7 @@ public class AdminCommands extends Thread
{
final PlayerInstance activeChar = clientShut.getActiveChar();
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Shutdown Server</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Shutdown Server</title>");
replyMSG.append("<body><br>");
replyMSG.append("Enter in seconds the time till the server<p> shutdowns bellow:");
replyMSG.append("<edit var=\"shutdown_time\" width=110>");
@@ -1044,14 +1044,13 @@ public class AdminCommands extends Thread
fis = new FileInputStream(file);
final byte[] raw = new byte[fis.available()];
fis.read(raw);
final String content = new String(raw, "UTF-8");
final String content = new String(raw, StandardCharsets.UTF_8);
final PlayerInstance activeChar = client.getActiveChar();
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
adminReply.setHtml(content);
activeChar.sendPacket(adminReply);
fis.close();
return;
}
catch (Exception e)
{
@@ -1100,7 +1099,7 @@ public class AdminCommands extends Thread
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(_characterToManipulate);
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Remove skills of " + player.getName() + "</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Remove skills of " + player.getName() + "</title>");
replyMSG.append("<body>");
replyMSG.append("<br>");
replyMSG.append("<center>Lv: " + player.getLevel() + " " + CharTemplateTable.getInstance().getTemplate(player.getClassId()).getClassName() + "<p>");
@@ -1131,7 +1130,7 @@ public class AdminCommands extends Thread
final PlayerInstance activeChar = client.getActiveChar();
final PlayerInstance player = World.getInstance().getPlayer(_characterToManipulate);
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Modify skills of " + player.getName() + "</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Modify skills of " + player.getName() + "</title>");
replyMSG.append("<body>");
replyMSG.append("<br>");
replyMSG.append("<center>Lv: " + player.getLevel() + " " + CharTemplateTable.getInstance().getTemplate(player.getClassId()).getClassName() + "<p>");
@@ -1261,24 +1260,12 @@ public class AdminCommands extends Thread
final PlayerInstance activeChar = client.getActiveChar();
final int skillid = Integer.parseInt(val);
final Skill skill = SkillTable.getInstance().getInfo(skillid, 1);
if (skill != null)
if ((skill != null) && (skill.getTargetType() == 0))
{
if (skill.getTargetType() == 0)
{
activeChar.setTarget(activeChar);
final MagicSkillUser msk = new MagicSkillUser(activeChar, skillid, 1, skill.getHitTime(), skill.getReuseDelay());
activeChar.sendPacket(msk);
activeChar.broadcastPacket(msk);
// ActionFailed af = new ActionFailed();
}
// else if (skill.getTargetType() == 1)
// {
// ActionFailed af = new ActionFailed();
// }
activeChar.setTarget(activeChar);
final MagicSkillUser msk = new MagicSkillUser(activeChar, skillid, 1, skill.getHitTime(), skill.getReuseDelay());
activeChar.sendPacket(msk);
activeChar.broadcastPacket(msk);
}
// else
// {
// ActionFailed af = new ActionFailed();
// }
}
}

View File

@@ -71,7 +71,7 @@ public class Announcements
{
for (int i = 0; i < _announcements.size(); ++i)
{
final CreatureSay cs = new CreatureSay(0, 10, activeChar.getName(), _announcements.get(i).toString());
final CreatureSay cs = new CreatureSay(0, 10, activeChar.getName(), _announcements.get(i));
activeChar.sendPacket(cs);
}
}
@@ -79,11 +79,11 @@ public class Announcements
public void listAnnouncements(PlayerInstance activeChar)
{
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
final StringBuffer replyMSG = new StringBuffer("<html><title>Announcements:</title>");
final StringBuilder replyMSG = new StringBuilder("<html><title>Announcements:</title>");
replyMSG.append("<body>");
for (int i = 0; i < _announcements.size(); ++i)
{
replyMSG.append(_announcements.get(i).toString());
replyMSG.append(_announcements.get(i));
replyMSG.append("<center><button value=\"Delete\" action=\"bypass -h admin_del_announcement " + i + "\" width=110 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>");
}
replyMSG.append("<br>");
@@ -149,7 +149,7 @@ public class Announcements
final FileWriter save = new FileWriter(new File("data/announcements.txt"));
for (int i = 0; i < _announcements.size(); ++i)
{
save.write(_announcements.get(i).toString());
save.write(_announcements.get(i));
save.write("\r\n");
}
save.close();

View File

@@ -130,9 +130,9 @@ public class GameServer extends Thread
if (!Config.SERVER_HOST_NAME.equals("*"))
{
final InetAddress adr = InetAddress.getByName(Config.SERVER_HOST_NAME);
Config._ip = adr.getHostAddress();
String ip = adr.getHostAddress();
_serverSocket = new ServerSocket(Config.SERVER_PORT, 50, adr);
_log.config("GameServer listening on IP:" + Config._ip + " Port " + Config.SERVER_PORT);
_log.config("GameServer listening on IP:" + ip + " Port " + Config.SERVER_PORT);
}
else
{

View File

@@ -66,7 +66,6 @@ public class GameTimeController extends Thread
}
catch (InterruptedException e1)
{
return;
}
}

View File

@@ -38,21 +38,20 @@ public class CharNameTable
private CharNameTable()
{
final File _accountsFolder = new File("data/accounts");
_accountsFolder.mkdirs();
final File accountsFolder = new File("data/accounts");
accountsFolder.mkdirs();
_charNames = new ArrayList<>();
final File[] accounts = _accountsFolder.listFiles();
final File[] accounts = accountsFolder.listFiles();
for (File account : accounts)
{
try
{
final File _charFolder = new File("data/accounts/" + account.getName());
final File[] chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_char.csv"));
final File charFolder = new File("data/accounts/" + account.getName());
final File[] chars = charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_char.csv"));
for (File c : chars)
{
_charNames.add(c.getName().replaceAll("_char.csv", "").toLowerCase());
}
continue;
}
catch (NullPointerException e)
{

View File

@@ -186,9 +186,9 @@ public class ItemTable
private void fixEtcItems(HashMap<Integer, Item> items)
{
for (int key : items.keySet())
for (Item i : items.values())
{
final EtcItem item = (EtcItem) items.get(key);
final EtcItem item = (EtcItem) i;
if ((item.getWeight() == 0) && (item.getEtcItemType() != EtcItem.TYPE_MONEY) && !item.getName().startsWith("world_map") && !item.getName().startsWith("crystal_"))
{
item.setType2(Item.TYPE2_QUEST);

View File

@@ -87,7 +87,7 @@ public class SpawnTable
}
}
private Spawn parseList(String line) throws SecurityException, ClassNotFoundException
private Spawn parseList(String line) throws ClassNotFoundException
{
final StringTokenizer st = new StringTokenizer(line, ";");
final int spawnId = Integer.parseInt(st.nextToken());
@@ -115,9 +115,9 @@ public class SpawnTable
return spawnDat;
}
public Spawn getTemplate(int Id)
public Spawn getTemplate(int id)
{
return _spawntable.get(Id);
return _spawntable.get(id);
}
public void addNewSpawn(Spawn spawn)

View File

@@ -43,27 +43,27 @@ public class Potions implements IItemHandler
@Override
public int useItem(PlayerInstance activeChar, ItemInstance item)
{
final Potion Potion = new Potion();
final Potion potion = new Potion();
final int itemId = item.getItemId();
if ((itemId == 65) || (itemId == 725) || (itemId == 727) || (itemId == 1060) || (itemId == 1061) || (itemId == 1539) || (itemId == 1540) || (itemId == 1073))
{
final WorldObject OldTarget = activeChar.getTarget();
final WorldObject oldTarget = activeChar.getTarget();
activeChar.setTarget(activeChar);
final MagicSkillUser MSU = new MagicSkillUser(activeChar, 2038, 1, 0, 0);
activeChar.sendPacket(MSU);
activeChar.broadcastPacket(MSU);
activeChar.setTarget(OldTarget);
Potion.setCurrentHpPotion1(activeChar, itemId);
final MagicSkillUser msu = new MagicSkillUser(activeChar, 2038, 1, 0, 0);
activeChar.sendPacket(msu);
activeChar.broadcastPacket(msu);
activeChar.setTarget(oldTarget);
potion.setCurrentHpPotion1(activeChar, itemId);
}
else if ((itemId == 726) || (itemId == 728))
{
final WorldObject OldTarget = activeChar.getTarget();
final WorldObject oldTarget = activeChar.getTarget();
activeChar.setTarget(activeChar);
final MagicSkillUser MSU = new MagicSkillUser(activeChar, 2038, 1, 0, 0);
activeChar.sendPacket(MSU);
activeChar.broadcastPacket(MSU);
activeChar.setTarget(OldTarget);
Potion.setCurrentMpPotion1(activeChar, itemId);
final MagicSkillUser msu = new MagicSkillUser(activeChar, 2038, 1, 0, 0);
activeChar.sendPacket(msu);
activeChar.broadcastPacket(msu);
activeChar.setTarget(oldTarget);
potion.setCurrentMpPotion1(activeChar, itemId);
}
return 1;
}

View File

@@ -72,12 +72,12 @@ public class SoulShots implements IItemHandler
}
activeChar.setActiveSoulshotGrade(grade);
activeChar.sendPacket(new SystemMessage(SystemMessage.ENABLED_SOULSHOT));
final WorldObject OldTarget = activeChar.getTarget();
final WorldObject oldTarget = activeChar.getTarget();
activeChar.setTarget(activeChar);
final MagicSkillUser MSU = new MagicSkillUser(activeChar, 2039, 1, 0, 0);
activeChar.sendPacket(MSU);
activeChar.broadcastPacket(MSU);
activeChar.setTarget(OldTarget);
final MagicSkillUser msu = new MagicSkillUser(activeChar, 2039, 1, 0, 0);
activeChar.sendPacket(msu);
activeChar.broadcastPacket(msu);
activeChar.setTarget(oldTarget);
return soulShotConsumption;
}

View File

@@ -52,7 +52,7 @@ public class CommunityBoardManager
final PlayerInstance activeChar = client.getActiveChar();
if (command.startsWith("bbs_"))
{
final StringBuffer htmlCode = new StringBuffer("<html imgsrc=\"sek.cbui353\"><body><br><table border=0><tr><td FIXWIDTH=15></td><td align=center>Community Board<img src=\"sek.cbui355\" width=610 height=1></td></tr><tr><td FIXWIDTH=15></td><td>");
final StringBuilder htmlCode = new StringBuilder("<html imgsrc=\"sek.cbui353\"><body><br><table border=0><tr><td FIXWIDTH=15></td><td align=center>Community Board<img src=\"sek.cbui355\" width=610 height=1></td></tr><tr><td FIXWIDTH=15></td><td>");
if (command.equals("bbs_default"))
{
final Collection<PlayerInstance> players = World.getInstance().getAllPlayers();
@@ -122,7 +122,7 @@ public class CommunityBoardManager
htmlCode.append("<tr><td><br></td></tr>");
for (ClanMember member : clan.getMembers())
{
if (member.getName() == clan.getLeaderName())
if (member.getName().equals(clan.getLeaderName()))
{
continue;
}

View File

@@ -19,17 +19,18 @@ package org.l2jmobius.gameserver.model;
public class Skill
{
public static int OP_ALWAYS = 1;
public static int OP_ONCE = 2;
public static int OP_DURATION = 3;
public static int OP_TOGGLE = 4;
public static int TARGET_SELF = 0;
public static int TARGET_ONE = 1;
public static int TARGET_PARTY = 2;
public static int TARGET_CLAN = 3;
public static int TARGET_PET = 4;
public static int TARGET_ENEMY = 5;
public static int TARGET_FRIEND = 6;
public static final int OP_ALWAYS = 1;
public static final int OP_ONCE = 2;
public static final int OP_DURATION = 3;
public static final int OP_TOGGLE = 4;
public static final int TARGET_SELF = 0;
public static final int TARGET_ONE = 1;
public static final int TARGET_PARTY = 2;
public static final int TARGET_CLAN = 3;
public static final int TARGET_PET = 4;
public static final int TARGET_ENEMY = 5;
public static final int TARGET_FRIEND = 6;
private int _id;
private int _level;
private String _name;

View File

@@ -46,7 +46,7 @@ public class Spawn
private int _respawnDelay;
private final Constructor<?> _constructor;
public Spawn(Npc mobTemplate) throws SecurityException, ClassNotFoundException
public Spawn(Npc mobTemplate) throws ClassNotFoundException
{
_template = mobTemplate;
final String implementationName = _template.getType();
@@ -182,14 +182,7 @@ public class Spawn
};
mob = (NpcInstance) _constructor.newInstance(parameters);
mob.setObjectId(IdFactory.getInstance().getNextId());
if (mob instanceof MonsterInstance)
{
mob.setAutoAttackable(true);
}
else
{
mob.setAutoAttackable(false);
}
mob.setAutoAttackable(mob instanceof MonsterInstance);
if (getRandomx() > 0)
{
final int random1 = Rnd.get(getRandomx());

View File

@@ -89,12 +89,12 @@ public class TradeList
return -1;
}
public ItemInstance getItem(int ObjectId)
public ItemInstance getItem(int objectId)
{
for (int i = 0; i < _items.size(); ++i)
{
final ItemInstance item = _items.get(i);
if (item.getObjectId() != ObjectId)
if (item.getObjectId() != objectId)
{
continue;
}
@@ -280,12 +280,12 @@ public class TradeList
}
else
{
msg = new SystemMessage(SystemMessage.S1_PURCHASED_S3_S2_s);
msg = new SystemMessage(SystemMessage.S1_PURCHASED_S3_S2_S);
msg.addString(buyer.getName());
msg.addItemName(((ItemInstance) sellerItem).getItemId());
msg.addNumber(amount);
sysmsgs.add(msg);
msg = new SystemMessage(SystemMessage.S1_PURCHASED_S3_S2_s);
msg = new SystemMessage(SystemMessage.S1_PURCHASED_S3_S2_S);
msg.addString("You");
msg.addItemName(((ItemInstance) sellerItem).getItemId());
msg.addNumber(amount);

View File

@@ -115,11 +115,10 @@ public class World
public void removeVisibleObject(WorldObject object)
{
_visibleObjects.remove(object.getObjectId());
for (Object element : object.getKnownObjects())
for (WorldObject wo : object.getKnownObjects())
{
final WorldObject temp1 = (WorldObject) element;
temp1.removeKnownObject(object);
object.removeKnownObject(temp1);
wo.removeKnownObject(object);
object.removeKnownObject(wo);
}
if (object instanceof PlayerInstance)
{

View File

@@ -31,7 +31,7 @@ public class WorldObject implements Serializable
private int _x;
private int _y;
private int _z;
protected Set<WorldObject> _knownObjects = ConcurrentHashMap.newKeySet();
protected final Set<WorldObject> _knownObjects = ConcurrentHashMap.newKeySet();
private final Set<PlayerInstance> _knownPlayers = ConcurrentHashMap.newKeySet();
public int getObjectId()

View File

@@ -110,24 +110,6 @@ public class Attackable extends NpcInstance
super.startAttack(target);
}
@Override
public void setX(int x)
{
super.setX(x);
}
@Override
public void setY(int y)
{
super.setY(y);
}
@Override
public void setZ(int z)
{
super.setZ(z);
}
@Override
public void removeKnownObject(WorldObject object)
{
@@ -153,8 +135,8 @@ public class Attackable extends NpcInstance
}
else if (isDead())
{
final Attackable Attackable = this;
synchronized (Attackable)
final Attackable attackable = this;
synchronized (attackable)
{
if (!_killedAlready)
{
@@ -263,14 +245,7 @@ public class Attackable extends NpcInstance
newAggro += aggroValue.intValue();
}
_aggroList.put(attacker, newAggro);
if (_aggroList.size() == 1)
{
setTarget(attacker);
}
else
{
setTarget(attacker);
}
setTarget(attacker);
}
public void doItemDrop()
@@ -298,12 +273,11 @@ public class Attackable extends NpcInstance
dropit.setZ(getZ() + 100);
dropit.setOnTheGround(true);
final DropItem dis = new DropItem(dropit, getObjectId());
for (Creature player : broadcastPacket(dis))
for (PlayerInstance player : broadcastPacket(dis))
{
((PlayerInstance) player).addKnownObjectWithoutCreate(dropit);
player.addKnownObjectWithoutCreate(dropit);
}
World.getInstance().addVisibleObject(dropit);
continue;
}
}
}
@@ -331,12 +305,6 @@ public class Attackable extends NpcInstance
}
}
@Override
public void setCurrentHp(double currentHp)
{
super.setCurrentHp(currentHp);
}
@Override
public Weapon getActiveWeapon()
{
@@ -409,7 +377,7 @@ public class Attackable extends NpcInstance
{
for (PlayerInstance player : getKnownPlayers())
{
if (!getCondition2(player) || !(getDistance(player.getX(), player.getY()) <= (getCollisionRadius() + 200.0)))
if (!getCondition2(player) || (getDistance(player.getX(), player.getY()) > (getCollisionRadius() + 200.0)))
{
continue;
}

View File

@@ -407,7 +407,6 @@ public abstract class Creature extends WorldObject
try
{
player.sendPacket(su);
continue;
}
catch (Exception e1)
{
@@ -879,7 +878,6 @@ public abstract class Creature extends WorldObject
{
sendPacket(new ActionFailed());
onTargetReached();
return;
}
}
@@ -1519,10 +1517,7 @@ public abstract class Creature extends WorldObject
setX(x);
setY(y);
setZ(z);
ThreadPool.schedule(() ->
{
World.getInstance().addVisibleObject(this);
}, 2000);
ThreadPool.schedule(() -> World.getInstance().addVisibleObject(this), 2000);
}
@Override

View File

@@ -35,12 +35,6 @@ public class MerchantInstance extends NpcInstance
super(template);
}
@Override
public void onAction(PlayerInstance player)
{
super.onAction(player);
}
@Override
public String getHtmlPath(int npcId, int val)
{

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model.actor.instance;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger;
@@ -58,6 +59,9 @@ public class NpcInstance extends Creature
_npcTemplate = template;
setCollisionHeight(template.getHeight());
setCollisionRadius(template.getRadius());
// TODO: Datapack support for name and title.
// setName(template.getName());
// setTitle(template.getTitle());
}
public boolean isAggressive()
@@ -171,7 +175,7 @@ public class NpcInstance extends Creature
if (client.getAccessLevel() >= 100)
{
final NpcHtmlMessage html = new NpcHtmlMessage(1);
final StringBuffer html1 = new StringBuffer("<html><body><table border=0>");
final StringBuilder html1 = new StringBuilder("<html><body><table border=0>");
html1.append("<tr><td>Current Target:</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td>Object ID: " + getObjectId() + "</td></tr>");
@@ -219,7 +223,7 @@ public class NpcInstance extends Creature
public void insertObjectIdAndShowChatWindow(PlayerInstance player, String content)
{
content = content.replaceAll("%objectId%", String.valueOf(getObjectId()));
content = content.replace("%objectId%", String.valueOf(getObjectId()));
final NpcHtmlMessage npcReply = new NpcHtmlMessage(5);
npcReply.setHtml(content);
player.sendPacket(npcReply);
@@ -265,7 +269,7 @@ public class NpcInstance extends Creature
FileInputStream fis = new FileInputStream(file);
final byte[] raw = new byte[fis.available()];
fis.read(raw);
final String content = new String(raw, "UTF-8");
final String content = new String(raw, StandardCharsets.UTF_8);
insertObjectIdAndShowChatWindow(player, content);
fis.close();
}
@@ -314,8 +318,7 @@ public class NpcInstance extends Creature
super.reduceCurrentHp(i, attacker);
if (isDead())
{
final NpcInstance NpcInstance = this;
synchronized (NpcInstance)
synchronized (this)
{
if ((_decayTask == null) || _decayTask.isCancelled() || _decayTask.isDone())
{

View File

@@ -353,8 +353,7 @@ public class PetInstance extends Creature
}
final ItemInstance target = (ItemInstance) getTarget();
boolean pickupOk = false;
final ItemInstance ItemInstance = target;
synchronized (ItemInstance)
synchronized (target)
{
if (target.isOnTheGround())
{
@@ -387,21 +386,13 @@ public class PetInstance extends Creature
public void reduceCurrentHp(int damage, Creature attacker)
{
super.reduceCurrentHp(damage, attacker);
if (!isDead() && (attacker != null))
if (!isDead() && (attacker != null) && !isInCombat())
{
if (!isInCombat())
{
startAttack(attacker);
}
// else
// {
// _log.fine("already attacking");
// }
startAttack(attacker);
}
if (isDead())
{
final PetInstance PetInstance = this;
synchronized (PetInstance)
synchronized (this)
{
if ((_decayTask == null) || _decayTask.isCancelled() || _decayTask.isDone())
{
@@ -445,10 +436,10 @@ public class PetInstance extends Creature
_owner.getInventory().addItem(item);
getInventory().dropItem(item, item.getCount());
final PetInventoryUpdate petiu = new PetInventoryUpdate();
final ItemList PlayerUI = new ItemList(_owner, false);
final ItemList playerUI = new ItemList(_owner, false);
petiu.addRemovedItem(item);
_owner.sendPacket(petiu);
_owner.sendPacket(PlayerUI);
_owner.sendPacket(playerUI);
}
catch (Exception e)
{
@@ -531,9 +522,9 @@ public class PetInstance extends Creature
dropit.setZ(getZ() + 100);
dropit.setOnTheGround(true);
final DropItem dis = new DropItem(dropit, getObjectId());
for (Creature player : broadcastPacket(dis))
for (PlayerInstance player : broadcastPacket(dis))
{
((PlayerInstance) player).addKnownObjectWithoutCreate(dropit);
player.addKnownObjectWithoutCreate(dropit);
}
World.getInstance().addVisibleObject(dropit);
}
@@ -586,11 +577,11 @@ public class PetInstance extends Creature
updateKnownCounter = (byte) (updateKnownCounter + 1);
if (updateKnownCounter > 3)
{
if (getKnownObjects().size() != 0)
if (!getKnownObjects().isEmpty())
{
for (WorldObject object : _knownObjects)
{
if (!(getDistance(object.getX(), object.getY()) > 4000.0))
if (getDistance(object.getX(), object.getY()) <= 4000.0)
{
continue;
}

View File

@@ -138,8 +138,7 @@ public class PlayerInstance extends Creature
public Skill addSkill(Skill newSkill)
{
final Skill oldSkill = _skills.put(newSkill.getId(), newSkill);
return oldSkill;
return _skills.put(newSkill.getId(), newSkill);
}
public Skill removeSkill(Skill skill)
@@ -720,6 +719,7 @@ public class PlayerInstance extends Creature
case CASTING:
{
useMagic(_skill);
break; // Use a fallthrou?
}
case INTERACT:
{
@@ -765,8 +765,7 @@ public class PlayerInstance extends Creature
final StopMove sm = new StopMove(getObjectId(), getX(), getY(), getZ(), getHeading());
sendPacket(sm);
boolean pickupOk = false;
final ItemInstance ItemInstance = target;
synchronized (ItemInstance)
synchronized (target)
{
if (target.isOnTheGround())
{
@@ -844,7 +843,7 @@ public class PlayerInstance extends Creature
((Creature) oldTarget).removeStatusListener(this);
}
}
if ((newTarget != null) && (newTarget instanceof Creature))
if (newTarget instanceof Creature)
{
((Creature) newTarget).addStatusListener(this);
}
@@ -1366,10 +1365,10 @@ public class PlayerInstance extends Creature
Armor armorPiece;
final double lvlBonus = (89.0 + getLevel()) / 100.0;
final StatModifiers modifier = CharStatsTable.getInstance().getTemplate(getClassId());
double MENbonus = 1.0;
double menBonus = 1.0;
if (modifier != null)
{
MENbonus = (100.0 + modifier.getModmen()) / 100.0;
menBonus = (100.0 + modifier.getModmen()) / 100.0;
}
else
{
@@ -1411,7 +1410,7 @@ public class PlayerInstance extends Creature
armorPiece = (Armor) dummy.getItem();
totalItemDef += armorPiece.getMDef();
}
final double mDef = totalItemDef * lvlBonus * MENbonus;
final double mDef = totalItemDef * lvlBonus * menBonus;
setMagicalDefense((int) Math.round(mDef));
}

View File

@@ -53,12 +53,6 @@ public class TeleporterInstance extends NpcInstance
return "data/html/teleporter/" + pom + ".htm";
}
@Override
public void onAction(PlayerInstance player)
{
super.onAction(player);
}
private void doTeleport(PlayerInstance player, int val)
{
final TeleportLocation list = TeleportLocationTable.getInstance().getTemplate(val);

View File

@@ -30,12 +30,6 @@ public class TrainerInstance extends NpcInstance
super(template);
}
@Override
public void onAction(PlayerInstance player)
{
super.onAction(player);
}
@Override
public String getHtmlPath(int npcId, int val)
{

View File

@@ -50,12 +50,6 @@ public class VillageMasterInstance extends NpcInstance
return "data/html/villagemaster/" + pom + ".htm";
}
@Override
public void onAction(PlayerInstance player)
{
super.onAction(player);
}
public void createClan(PlayerInstance player, String clanName)
{
if (player.getLevel() < 10)

View File

@@ -35,12 +35,6 @@ public class WarehouseInstance extends NpcInstance
super(template);
}
@Override
public void onAction(PlayerInstance player)
{
super.onAction(player);
}
@Override
public String getHtmlPath(int npcId, int val)
{

View File

@@ -284,7 +284,7 @@ public class ClientThread extends Thread
}
else
{
_log.warning("could not restore " + chars[charslot]);
_log.warning("Could not restore " + chars[charslot]);
}
return character;
}

View File

@@ -124,7 +124,7 @@ public class Connection
int a;
int charpoint;
byte t1;
final StringBuffer result = new StringBuffer();
final StringBuilder result = new StringBuilder();
int counter = 0;
for (int i = 0; i < len; ++i)
{

View File

@@ -544,7 +544,7 @@ public class PacketHandler
int a;
int charpoint;
byte t1;
final StringBuffer result = new StringBuffer();
final StringBuilder result = new StringBuilder();
int counter = 0;
for (int i = 0; i < len; ++i)
{

View File

@@ -42,7 +42,7 @@ public class AddTradeItem extends ClientBasePacket
final TradeList playerItemList = player.getTradeList();
player.getTradeList().setConfirmedTrade(false);
requestor.getTradeList().setConfirmedTrade(false);
if (playerItemList.getItems().size() > 0)
if (!playerItemList.getItems().isEmpty())
{
if (!playerItemList.contains(objectId))
{

View File

@@ -27,7 +27,7 @@ import org.l2jmobius.loginserver.LoginController;
public class AuthLogin extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(AuthLogin.class.getName());
private static final Logger _log = Logger.getLogger(AuthLogin.class.getName());
public AuthLogin(byte[] decrypt, ClientThread client) throws IOException
{

View File

@@ -17,7 +17,6 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.l2jmobius.gameserver.IdFactory;
@@ -91,7 +90,7 @@ public class CharacterCreate extends ClientBasePacket
return result;
}
private void initNewChar(ClientThread client, PlayerInstance newChar) throws FileNotFoundException, IOException
private void initNewChar(ClientThread client, PlayerInstance newChar) throws IOException
{
newChar.setObjectId(IdFactory.getInstance().getNextId());
World.getInstance().storeObject(newChar);

View File

@@ -17,6 +17,8 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.nio.charset.StandardCharsets;
public abstract class ClientBasePacket
{
private final byte[] _decrypt;
@@ -65,7 +67,7 @@ public abstract class ClientBasePacket
String result = null;
try
{
result = new String(_decrypt, _off, _decrypt.length - _off, "UTF-16LE");
result = new String(_decrypt, _off, _decrypt.length - _off, StandardCharsets.UTF_16LE);
result = result.substring(0, result.indexOf(0));
}
catch (Exception e)

View File

@@ -35,7 +35,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
public class EnterWorld extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(EnterWorld.class.getName());
private static final Logger _log = Logger.getLogger(EnterWorld.class.getName());
public EnterWorld(byte[] decrypt, ClientThread client)
{

View File

@@ -27,7 +27,7 @@ import org.l2jmobius.gameserver.network.serverpackets.KeyPacket;
public class ProtocolVersion extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(ProtocolVersion.class.getName());
private static final Logger _log = Logger.getLogger(ProtocolVersion.class.getName());
public ProtocolVersion(byte[] rawPacket, ClientThread client) throws IOException
{

View File

@@ -30,7 +30,7 @@ import org.l2jmobius.gameserver.network.serverpackets.StopMove;
public class RequestActionUse extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestActionUse.class.getName());
private static final Logger _log = Logger.getLogger(RequestActionUse.class.getName());
public RequestActionUse(byte[] rawPacket, ClientThread client)
{

View File

@@ -26,7 +26,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AllyCrest;
public class RequestAllyCrest extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestAllyCrest.class.getName());
private static final Logger _log = Logger.getLogger(RequestAllyCrest.class.getName());
public RequestAllyCrest(byte[] rawPacket, ClientThread client) throws IOException
{

View File

@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class RequestBuyItem extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestBuyItem.class.getName());
private static final Logger _log = Logger.getLogger(RequestBuyItem.class.getName());
public RequestBuyItem(byte[] decrypt, ClientThread client)
{

View File

@@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.network.ClientThread;
public class RequestBypassToServer extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
private static final Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
public RequestBypassToServer(byte[] decrypt, ClientThread client)
{

View File

@@ -20,7 +20,6 @@ package org.l2jmobius.gameserver.network.clientpackets;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.ClientThread;
@@ -31,7 +30,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
public class RequestDropItem extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestDropItem.class.getName());
private static final Logger _log = Logger.getLogger(RequestDropItem.class.getName());
public RequestDropItem(byte[] decrypt, ClientThread client)
{
@@ -87,9 +86,9 @@ public class RequestDropItem extends ClientBasePacket
final DropItem di = new DropItem(dropedItem, activeChar.getObjectId());
activeChar.sendPacket(di);
activeChar.addKnownObjectWithoutCreate(dropedItem);
for (Creature player : activeChar.broadcastPacket(di))
for (PlayerInstance player : activeChar.broadcastPacket(di))
{
((PlayerInstance) player).addKnownObjectWithoutCreate(dropedItem);
player.addKnownObjectWithoutCreate(dropedItem);
}
final InventoryUpdate iu = new InventoryUpdate();
if (oldCount == dropedItem.getCount())

View File

@@ -27,7 +27,7 @@ import org.l2jmobius.gameserver.network.serverpackets.PetInventoryUpdate;
public class RequestGetItemFromPet extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestGetItemFromPet.class.getName());
private static final Logger _log = Logger.getLogger(RequestGetItemFromPet.class.getName());
public RequestGetItemFromPet(byte[] decrypt, ClientThread client)
{

View File

@@ -28,7 +28,7 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class RequestJoinParty extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestJoinParty.class.getName());
private static final Logger _log = Logger.getLogger(RequestJoinParty.class.getName());
public RequestJoinParty(byte[] decrypt, ClientThread client)
{
@@ -120,9 +120,5 @@ public class RequestJoinParty extends ClientBasePacket
_log.warning(requestor.getName() + " already received a party invitation");
}
}
else if (target.getKnownPlayers().contains(requestor))
{
_log.warning(client.getActiveChar().getName() + " invited someone who doesn't know him.");
}
}
}

View File

@@ -26,7 +26,7 @@ import org.l2jmobius.gameserver.network.ClientThread;
public class RequestMagicSkillUse extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestMagicSkillUse.class.getName());
private static final Logger _log = Logger.getLogger(RequestMagicSkillUse.class.getName());
public RequestMagicSkillUse(byte[] rawPacket, ClientThread client)
{

View File

@@ -31,7 +31,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
public class RequestOustPledgeMember extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestOustPledgeMember.class.getName());
private static final Logger _log = Logger.getLogger(RequestOustPledgeMember.class.getName());
public RequestOustPledgeMember(byte[] rawPacket, ClientThread client)
{

View File

@@ -26,7 +26,7 @@ import org.l2jmobius.gameserver.network.serverpackets.PledgeCrest;
public class RequestPledgeCrest extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestPledgeCrest.class.getName());
private static final Logger _log = Logger.getLogger(RequestPledgeCrest.class.getName());
public RequestPledgeCrest(byte[] rawPacket, ClientThread client) throws IOException
{

View File

@@ -28,7 +28,7 @@ import org.l2jmobius.gameserver.network.serverpackets.PledgeShowMemberListAll;
public class RequestPledgeInfo extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(RequestPledgeInfo.class.getName());
private static final Logger _log = Logger.getLogger(RequestPledgeInfo.class.getName());
public RequestPledgeInfo(byte[] rawPacket, ClientThread client)
{

View File

@@ -50,7 +50,7 @@ public class RequestUnEquipItem extends ClientBasePacket
activeChar.setAttackStatus(false);
final CharInfo info = new CharInfo(activeChar);
activeChar.broadcastPacket(info);
if (unequiped.size() > 0)
if (!unequiped.isEmpty())
{
final SystemMessage sm = new SystemMessage(SystemMessage.S1_DISARMED);
sm.addItemName(unequiped.stream().findFirst().get().getItemId());

View File

@@ -55,7 +55,7 @@ public class SendPrivateStoreBuyBuyList extends ClientBasePacket
{
buyer.getTradeList().BuySellItems(buyer, buyerlist, seller, sellerlist);
buyer.getTradeList().updateBuyList(buyer, buyerlist);
if (buyer.getBuyList().size() == 0)
if (buyer.getBuyList().isEmpty())
{
buyer.setPrivateStoreType(0);
buyer.sendPacket(new ChangeWaitType(buyer, 1));

View File

@@ -54,7 +54,7 @@ public class SendPrivateStoreBuyList extends ClientBasePacket
if ((buyer.getAdena() >= cost) && (count > 0) && (seller.getPrivateStoreType() == 1))
{
seller.getTradeList().BuySellItems(buyer, buyerlist, seller, sellerlist);
if (seller.getSellList().size() == 0)
if (seller.getSellList().isEmpty())
{
seller.setPrivateStoreType(0);
seller.sendPacket(new ChangeWaitType(seller, 1));

View File

@@ -28,7 +28,7 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class TradeRequest extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(TradeRequest.class.getName());
private static final Logger _log = Logger.getLogger(TradeRequest.class.getName());
public TradeRequest(byte[] decrypt, ClientThread client)
{
@@ -37,7 +37,7 @@ public class TradeRequest extends ClientBasePacket
final PlayerInstance player = client.getActiveChar();
final World world = World.getInstance();
final WorldObject target = world.findObject(objectId);
if ((target == null) || !(target instanceof PlayerInstance) || (target.getObjectId() != objectId))
if (!(target instanceof PlayerInstance) || (target.getObjectId() != objectId))
{
player.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT));
return;

View File

@@ -32,7 +32,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
public class UseItem extends ClientBasePacket
{
final static Logger _log = Logger.getLogger(UseItem.class.getName());
private static final Logger _log = Logger.getLogger(UseItem.class.getName());
public UseItem(byte[] decrypt, ClientThread client)
{

View File

@@ -19,17 +19,18 @@ package org.l2jmobius.gameserver.network.serverpackets;
public class AuthLoginFail extends ServerBasePacket
{
public static int NO_TEXT = 0;
public static int SYSTEM_ERROR_LOGIN_LATER = 1;
public static int PASSWORD_DOES_NOT_MATCH_THIS_ACCOUNT = 2;
public static int PASSWORD_DOES_NOT_MATCH_THIS_ACCOUNT2 = 3;
public static int ACCESS_FAILED_TRY_LATER = 4;
public static int INCORRECT_ACCOUNT_INFO_CONTACT_CUSTOMER_SUPPORT = 5;
public static int ACCESS_FAILED_TRY_LATER2 = 6;
public static int ACOUNT_ALREADY_IN_USE = 7;
public static int ACCESS_FAILED_TRY_LATER3 = 8;
public static int ACCESS_FAILED_TRY_LATER4 = 9;
public static int ACCESS_FAILED_TRY_LATER5 = 10;
public static final int NO_TEXT = 0;
public static final int SYSTEM_ERROR_LOGIN_LATER = 1;
public static final int PASSWORD_DOES_NOT_MATCH_THIS_ACCOUNT = 2;
public static final int PASSWORD_DOES_NOT_MATCH_THIS_ACCOUNT2 = 3;
public static final int ACCESS_FAILED_TRY_LATER = 4;
public static final int INCORRECT_ACCOUNT_INFO_CONTACT_CUSTOMER_SUPPORT = 5;
public static final int ACCESS_FAILED_TRY_LATER2 = 6;
public static final int ACOUNT_ALREADY_IN_USE = 7;
public static final int ACCESS_FAILED_TRY_LATER3 = 8;
public static final int ACCESS_FAILED_TRY_LATER4 = 9;
public static final int ACCESS_FAILED_TRY_LATER5 = 10;
private final int _reason;
public AuthLoginFail(int reason)

View File

@@ -21,8 +21,8 @@ import org.l2jmobius.gameserver.model.actor.Creature;
public class ChangeMoveType extends ServerBasePacket
{
public static int WALK = 0;
public static int RUN = 1;
public static final int WALK = 0;
public static final int RUN = 1;
private final Creature _cha;
private final int _moveType;

View File

@@ -19,10 +19,10 @@ package org.l2jmobius.gameserver.network.serverpackets;
public class CharCreateFail extends ServerBasePacket
{
public static int REASON_CREATION_FAILED = 0;
public static int REASON_TOO_MANY_CHARACTERS = 1;
public static int REASON_NAME_ALREADY_EXISTS = 2;
public static int REASON_16_ENG_CHARS = 3;
public static final int REASON_CREATION_FAILED = 0;
public static final int REASON_TOO_MANY_CHARACTERS = 1;
public static final int REASON_NAME_ALREADY_EXISTS = 2;
public static final int REASON_16_ENG_CHARS = 3;
private final int _error;

View File

@@ -121,9 +121,9 @@ public class CharSelectInfo extends ServerBasePacket
public CharSelectInfoPackage[] loadCharacterSelectInfoFromDisk()
{
final File _charFolder = new File("data/accounts", _loginName);
_charFolder.mkdirs();
final File[] chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_char.csv"));
final File charFolder = new File("data/accounts", _loginName);
charFolder.mkdirs();
final File[] chars = charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_char.csv"));
_charNameList = new String[chars.length];
final CharSelectInfoPackage[] characters = new CharSelectInfoPackage[chars.length];
for (int i = 0; i < chars.length; ++i)
@@ -132,12 +132,10 @@ public class CharSelectInfo extends ServerBasePacket
restoreChar(chars[i]);
if (_charInfopackage != null)
{
restoreInventory(new File(_charFolder, _charInfopackage.getName() + "_items.csv"));
restoreInventory(new File(charFolder, _charInfopackage.getName() + "_items.csv"));
characters[i] = _charInfopackage;
_charNameList[i] = _charInfopackage.getName();
continue;
}
// _log.warning("could not restore " + chars[i]);
}
return characters;
}

View File

@@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.network.serverpackets;
public class KeyPacket extends ServerBasePacket
{
final private byte[] _key;
private final byte[] _key;
public KeyPacket(byte[] key)
{

View File

@@ -41,16 +41,15 @@ public class PrivateSellListBuy extends ServerBasePacket
writeD(_buyer.getAdena());
final TradeList list = new TradeList(0);
final List<TradeItem> buyList = _buyer.getBuyList();
int count = _buyer.getInventory().getSize();
for (ItemInstance item : _buyer.getInventory().getItems())
{
if (item.isEquipped() || (item.getItem().getType2() == 3) || ((item.getItem().getType2() == 4) && (item.getItem().getType1() == 4)) || ((item.getItem().getType2() == 1) && (item.getItem().getType1() == 1)) || item.isEquipped())
if (item.isEquipped() || (item.getItem().getType2() == 3) || ((item.getItem().getType2() == 4) && (item.getItem().getType1() == 4)) || ((item.getItem().getType2() == 1) && (item.getItem().getType1() == 1)))
{
continue;
}
list.addItem(item);
}
count = list.getItems().size();
int count = list.getItems().size();
writeD(count);
for (ItemInstance item : list.getItems())
{

View File

@@ -41,23 +41,22 @@ public class PrivateSellListSell extends ServerBasePacket
writeD(_seller.getAdena());
final TradeList list = new TradeList(0);
final List<TradeItem> sellList = _seller.getSellList();
int count = _seller.getInventory().getSize();
for (ItemInstance item : _seller.getInventory().getItems())
{
if (item.isEquipped() || (item.getItem().getType2() == 3) || ((item.getItem().getType2() == 4) && (item.getItem().getType1() == 4)) || ((item.getItem().getType2() == 1) && (item.getItem().getType1() == 1)) || item.isEquipped())
if (item.isEquipped() || (item.getItem().getType2() == 3) || ((item.getItem().getType2() == 4) && (item.getItem().getType1() == 4)) || ((item.getItem().getType2() == 1) && (item.getItem().getType1() == 1)))
{
continue;
}
list.addItem(item);
}
if (sellList.size() != 0)
if (!sellList.isEmpty())
{
for (TradeItem tradeItem : sellList)
{
list.removeItem(tradeItem.getObjectId(), tradeItem.getCount());
}
}
count = list.getItems().size();
int count = list.getItems().size();
writeD(count);
for (ItemInstance item : list.getItems())
{

View File

@@ -19,13 +19,13 @@ package org.l2jmobius.gameserver.network.serverpackets;
public class RestartResponse extends ServerBasePacket
{
private static final String _message = "ok merong~ khaha";
private static final String MESSAGE = "ok merong~ khaha";
@Override
public void writeImpl()
{
writeC(0x74);
writeD(1);
writeS(_message);
writeS(MESSAGE);
}
}

View File

@@ -41,7 +41,6 @@ public class SellList extends ServerBasePacket
writeC(0x1C);
writeD(_money);
writeD(0);
int count = _char.getInventory().getSize();
for (ItemInstance item : _char.getInventory().getItems())
{
if (item.isEquipped() || (item.getItemId() == 57) || (item.getItem().getType2() == 3))
@@ -50,8 +49,7 @@ public class SellList extends ServerBasePacket
}
_selllist.add(item);
}
count = _selllist.size();
writeH(count);
writeH(_selllist.size());
for (ItemInstance item : _selllist)
{
writeH(item.getItem().getType1());

View File

@@ -18,6 +18,7 @@
package org.l2jmobius.gameserver.network.serverpackets;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
public abstract class ServerBasePacket
{
@@ -61,7 +62,7 @@ public abstract class ServerBasePacket
{
if (text != null)
{
_bao.write(text.getBytes("UTF-16LE"));
_bao.write(text.getBytes(StandardCharsets.UTF_16LE));
}
}
catch (Exception e)

View File

@@ -22,32 +22,32 @@ import java.util.List;
public class StatusUpdate extends ServerBasePacket
{
public static int LEVEL = 1;
public static int EXP = 2;
public static int STR = 3;
public static int DEX = 4;
public static int CON = 5;
public static int INT = 6;
public static int WIT = 7;
public static int MEN = 8;
public static int CUR_HP = 9;
public static int MAX_HP = 10;
public static int CUR_MP = 11;
public static int MAX_MP = 12;
public static int SP = 13;
public static int CUR_LOAD = 14;
public static int MAX_LOAD = 15;
public static int P_ATK = 17;
public static int ATK_SPD = 18;
public static int P_DEF = 19;
public static int EVASION = 20;
public static int ACCURACY = 21;
public static int CRITICAL = 22;
public static int M_ATK = 23;
public static int CAST_SPD = 24;
public static int M_DEF = 25;
public static int PVP_FLAG = 26;
public static int KARMA = 27;
public static final int LEVEL = 1;
public static final int EXP = 2;
public static final int STR = 3;
public static final int DEX = 4;
public static final int CON = 5;
public static final int INT = 6;
public static final int WIT = 7;
public static final int MEN = 8;
public static final int CUR_HP = 9;
public static final int MAX_HP = 10;
public static final int CUR_MP = 11;
public static final int MAX_MP = 12;
public static final int SP = 13;
public static final int CUR_LOAD = 14;
public static final int MAX_LOAD = 15;
public static final int P_ATK = 17;
public static final int ATK_SPD = 18;
public static final int P_DEF = 19;
public static final int EVASION = 20;
public static final int ACCURACY = 21;
public static final int CRITICAL = 22;
public static final int M_ATK = 23;
public static final int CAST_SPD = 24;
public static final int M_DEF = 25;
public static final int PVP_FLAG = 26;
public static final int KARMA = 27;
private final int _objectId;
private final List<Attribute> _attributes = new ArrayList<>();

View File

@@ -101,12 +101,12 @@ public class SystemMessage extends ServerBasePacket
public static final int ENABLED_SOULSHOT = 342;
public static final int S1_PURCHASED_S2 = 378;
public static final int S1_PURCHASED_S2_S3 = 379;
public static final int S1_PURCHASED_S3_S2_s = 380;
public static final int S1_PURCHASED_S3_S2_S = 380;
public static final int S1_DISARMED = 417;
public static final int WEIGHT_LIMIT_EXCEEDED = 422;
public static final int PURCHASED_S2_FROM_S1 = 559;
public static final int PURCHASED_S2_S3_FROM_S1 = 560;
public static final int PURCHASED_S3_S2_s_FROM_S1 = 561;
public static final int PURCHASED_S3_S2_S_FROM_S1 = 561;
public static final int S1_INVITED_YOU_TO_PARTY_FINDER_KEEPER = 572;
public static final int S1_INVITED_YOU_TO_PARTY_RANDOM = 573;
public static final int S1_S2 = 614;

View File

@@ -38,7 +38,6 @@ public class TradeStart extends ServerBasePacket
{
writeC(0x2E);
writeD(_me.getTransactionRequester().getObjectId());
int count = _me.getInventory().getSize();
for (ItemInstance item : _me.getInventory().getItems())
{
if (item.isEquipped() || (item.getItem().getType2() == 3))
@@ -47,7 +46,7 @@ public class TradeStart extends ServerBasePacket
}
_tradelist.add(item);
}
count = _tradelist.size();
int count = _tradelist.size();
writeH(count);
for (int i = 0; i < count; ++i)
{

View File

@@ -41,7 +41,6 @@ public class WareHouseDepositList extends ServerBasePacket
writeC(0x53);
writeD(_money);
final List<ItemInstance> itemlist = new ArrayList<>();
int count = _cha.getInventory().getSize();
for (ItemInstance item : _cha.getInventory().getItems())
{
if (item.isEquipped() || (item.getItem().getType2() == 3))
@@ -50,7 +49,7 @@ public class WareHouseDepositList extends ServerBasePacket
}
itemlist.add(item);
}
count = itemlist.size();
int count = itemlist.size();
writeH(count);
for (i = 0; i < count; ++i)
{

View File

@@ -29,6 +29,7 @@ public class Npc
private double _radius;
private double _height;
private String _name;
private String _title;
private String _sex;
private int _level;
private int _attackRange;
@@ -250,6 +251,11 @@ public class Npc
_name = name;
}
public void setTitle(String title)
{
_title = title;
}
public void setType(String type)
{
_type = type;
@@ -275,6 +281,11 @@ public class Npc
return _name;
}
public String getTitle()
{
return _title;
}
public int getNpcId()
{
return _npcId;

View File

@@ -52,10 +52,7 @@ public class ThreadPool
INSTANT_POOL.prestartAllCoreThreads();
// Launch purge task.
scheduleAtFixedRate(() ->
{
purge();
}, 60000, 60000);
scheduleAtFixedRate(ThreadPool::purge, 60000, 60000);
LOGGER.info("ThreadPool: Initialized");
LOGGER.info("...scheduled pool executor with " + Config.SCHEDULED_THREAD_POOL_COUNT + " total threads.");
@@ -166,7 +163,7 @@ public class ThreadPool
}
catch (Throwable t)
{
t.printStackTrace();
LOGGER.info("ThreadPool: Problem at Shutting down. " + t.getMessage());
}
}
}

View File

@@ -109,7 +109,7 @@ public class Gui
final String input = ((String) answer).trim();
if (Util.isDigit(input))
{
final int delay = Integer.valueOf(input);
final int delay = Integer.parseInt(input);
if (delay > 0)
{
AdminCommands.getInstance().serverShutdown(null, delay);
@@ -170,10 +170,7 @@ public class Gui
{
final JMenuItem mntmFont = new JMenuItem(font);
mntmFont.setFont(new Font("Segoe UI", Font.PLAIN, 13));
mntmFont.addActionListener(arg0 ->
{
txtrConsole.setFont(new Font("Monospaced", Font.PLAIN, Integer.parseInt(font)));
});
mntmFont.addActionListener(arg0 -> txtrConsole.setFont(new Font("Monospaced", Font.PLAIN, Integer.parseInt(font))));
mnFont.add(mntmFont);
}
@@ -183,10 +180,7 @@ public class Gui
final JMenuItem mntmAbout = new JMenuItem("About");
mntmAbout.setFont(new Font("Segoe UI", Font.PLAIN, 13));
mntmAbout.addActionListener(arg0 ->
{
new frmAbout();
});
mntmAbout.addActionListener(arg0 -> new frmAbout());
mnHelp.add(mntmAbout);
// Set icons.

View File

@@ -41,7 +41,7 @@ import org.l2jmobius.util.Locator;
*/
public class SystemPanel extends JPanel
{
static final long startTime = System.currentTimeMillis();
static final long START_TIME = System.currentTimeMillis();
public SystemPanel()
{
@@ -98,6 +98,7 @@ public class SystemPanel extends JPanel
}
catch (Exception e)
{
// Handled above.
}
// Initial update task.
@@ -118,7 +119,7 @@ public class SystemPanel extends JPanel
{
lblConnected.setText("Connected: " + World.getInstance().getAllPlayers().size());
lblMaxConnected.setText("Max connected: " + PlayerCountManager.getInstance().getMaxConnectedCount());
lblElapsedTime.setText("Elapsed: " + getDurationBreakdown(System.currentTimeMillis() - startTime));
lblElapsedTime.setText("Elapsed: " + getDurationBreakdown(System.currentTimeMillis() - START_TIME));
}
}, 1000, 1000);
}

View File

@@ -25,10 +25,6 @@ import java.util.logging.LogManager;
*/
public class ServerLogManager extends LogManager
{
public ServerLogManager()
{
}
@Override
public void reset()
{

View File

@@ -22,7 +22,7 @@ import java.util.logging.FileHandler;
public class ErrorLogHandler extends FileHandler
{
public ErrorLogHandler() throws IOException, SecurityException
public ErrorLogHandler() throws IOException
{
super();
}

View File

@@ -47,12 +47,12 @@ public class LoginController
return _instance;
}
public int assignSessionKeyToLogin(String account, int accessLevel, Socket _csocket)
public int assignSessionKeyToLogin(String account, int accessLevel, Socket cSocket)
{
int key = -1;
key = (int) System.currentTimeMillis() & 0xFFFFFF;
_logins.put(account, key);
_accountsInLoginServer.put(account, _csocket);
_accountsInLoginServer.put(account, cSocket);
_accessLevels.put(account, accessLevel);
return key;
}

View File

@@ -72,7 +72,6 @@ public class LoginServer extends Thread
}
catch (IOException e)
{
continue;
}
}
while (true);

View File

@@ -24,9 +24,11 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Base64;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
@@ -38,7 +40,6 @@ public class AccountData
{
private static Logger _log = Logger.getLogger(AccountData.class.getName());
private static final String SHA = "SHA";
private static final String UTF_8 = "UTF-8";
private static final Map<String, byte[]> _logPass = new ConcurrentHashMap<>();
private static final Map<String, Integer> _accessLevels = new ConcurrentHashMap<>();
private static final Map<String, Integer> _hackProtection = new ConcurrentHashMap<>();
@@ -78,7 +79,7 @@ public class AccountData
try
{
final MessageDigest md = MessageDigest.getInstance(SHA);
final byte[] raw = password.getBytes(UTF_8);
final byte[] raw = password.getBytes(StandardCharsets.UTF_8);
final byte[] hash = md.digest(raw);
final byte[] expected = _logPass.get(user);
if (expected == null)
@@ -128,7 +129,7 @@ public class AccountData
return ok;
}
private void readFromDisk(File loginFile) throws NumberFormatException, IOException
private void readFromDisk(File loginFile) throws IOException
{
_logPass.clear();
int i = 0;
@@ -165,11 +166,12 @@ public class AccountData
try
{
final FileWriter writer = new FileWriter(new File("data/accounts.txt"));
for (String name : _logPass.keySet())
for (Entry<String, byte[]> entry : _logPass.entrySet())
{
final String name = entry.getKey();
writer.write(name);
writer.write("\t");
writer.write(Base64.getEncoder().encodeToString(_logPass.get(name)));
writer.write(Base64.getEncoder().encodeToString(entry.getValue()));
writer.write("\t");
writer.write("" + _accessLevels.get(name));
writer.write("\r\n");

View File

@@ -41,7 +41,8 @@ import org.l2jmobius.loginserver.network.serverpackets.ServerList;
public class ClientThread extends Thread
{
private final static Logger _log = Logger.getLogger(ClientThread.class.getName());
private static final Logger _log = Logger.getLogger(ClientThread.class.getName());
private final InputStream _in;
private final OutputStream _out;
private final NewCrypt _crypt;
@@ -243,7 +244,7 @@ public class ClientThread extends Thread
int a;
int charpoint;
byte t1;
final StringBuffer result = new StringBuffer();
final StringBuilder result = new StringBuilder();
int counter = 0;
for (int i = 0; i < len; ++i)
{
@@ -305,7 +306,7 @@ public class ClientThread extends Thread
@SuppressWarnings("unused")
private String getTerminatedString(byte[] data, int offset)
{
final StringBuffer result = new StringBuffer();
final StringBuilder result = new StringBuilder();
for (int i = offset; (i < data.length) && (data[i] != 0); ++i)
{
result.append((char) data[i]);

View File

@@ -19,7 +19,7 @@ package org.l2jmobius.loginserver.network;
public class HackingException extends Exception
{
String _ip;
private final String _ip;
public HackingException(String ip)
{

View File

@@ -17,6 +17,8 @@
*/
package org.l2jmobius.loginserver.network.clientpackets;
import java.nio.charset.StandardCharsets;
public abstract class ClientBasePacket
{
private final byte[] _decrypt;
@@ -38,8 +40,7 @@ public abstract class ClientBasePacket
public int readC()
{
final int result = _decrypt[_off++] & 0xFF;
return result;
return _decrypt[_off++] & 0xFF;
}
public int readH()
@@ -65,7 +66,7 @@ public abstract class ClientBasePacket
String result = null;
try
{
result = new String(_decrypt, _off, _decrypt.length - _off, "UTF-16LE");
result = new String(_decrypt, _off, _decrypt.length - _off, StandardCharsets.UTF_16LE);
result = result.substring(0, result.indexOf(0));
}
catch (Exception e)

View File

@@ -19,11 +19,11 @@ package org.l2jmobius.loginserver.network.serverpackets;
public class PlayFail extends ServerBasePacket
{
public static int REASON_TOO_MANY_PLAYERS = 15;
public static int REASON1 = 1;
public static int REASON2 = 2;
public static int REASON3 = 3;
public static int REASON4 = 4;
public static final int REASON_TOO_MANY_PLAYERS = 15;
public static final int REASON1 = 1;
public static final int REASON2 = 2;
public static final int REASON3 = 3;
public static final int REASON4 = 4;
private final int _reason;

View File

@@ -18,6 +18,7 @@
package org.l2jmobius.loginserver.network.serverpackets;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
public abstract class ServerBasePacket
{
@@ -61,7 +62,7 @@ public abstract class ServerBasePacket
{
if (text != null)
{
_bao.write(text.getBytes("UTF-16LE"));
_bao.write(text.getBytes(StandardCharsets.UTF_16LE));
}
}
catch (Exception e)

View File

@@ -24,6 +24,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
@@ -99,10 +100,10 @@ public class AccountManager
private static void printAccInfo(String fin) throws FileNotFoundException, IOException
{
final File _test = new File(fin);
if (!_test.exists())
final File test = new File(fin);
if (!test.exists())
{
_test.createNewFile();
test.createNewFile();
}
final FileInputStream in = new FileInputStream(fin);
@SuppressWarnings("resource")
@@ -121,15 +122,15 @@ public class AccountManager
private static void updateAccounts(String fin, String fout) throws FileNotFoundException, IOException, NoSuchAlgorithmException
{
final File _test = new File(fin);
if (!_test.exists())
final File test = new File(fin);
if (!test.exists())
{
_test.createNewFile();
test.createNewFile();
}
final FileInputStream in = new FileInputStream(fin);
final FileWriter out = new FileWriter(fout);
final MessageDigest md = MessageDigest.getInstance("SHA");
byte[] newpass = _pass.getBytes("UTF-8");
byte[] newpass = _pass.getBytes(StandardCharsets.UTF_8);
newpass = md.digest(newpass);
try
{
@@ -159,7 +160,7 @@ public class AccountManager
System.out.println("Account for user " + _uname + " deleted");
}
}
if (line == "")
if (line.equals(""))
{
continue;
}
@@ -177,10 +178,10 @@ public class AccountManager
{
out.close();
in.close();
final File _fin = new File(fin);
final File _fout = new File(fout);
_fin.delete();
_fout.renameTo(_fin);
final File fileIn = new File(fin);
final File fileOut = new File(fout);
fileIn.delete();
fileOut.renameTo(fileIn);
}
catch (Exception e)
{
@@ -191,10 +192,10 @@ public class AccountManager
{
out.close();
in.close();
final File _fin = new File(fin);
final File _fout = new File(fout);
_fin.delete();
_fout.renameTo(_fin);
final File fileIn = new File(fin);
final File fileOut = new File(fout);
fileIn.delete();
fileOut.renameTo(fileIn);
}
catch (Exception e)
{

View File

@@ -77,7 +77,7 @@ public class Locator
final String u = url.toString();
if (u.startsWith("jar:file:"))
{
final int pling = u.indexOf("!");
final int pling = u.indexOf('!');
final String jarName = u.substring(4, pling);
return new File(fromURI(jarName));
}
@@ -118,7 +118,7 @@ public class Locator
{
throw new IllegalArgumentException("Can only handle valid file: URIs");
}
final StringBuffer buf = new StringBuffer(url.getHost());
final StringBuilder buf = new StringBuilder(url.getHost());
if (buf.length() > 0)
{
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
@@ -133,8 +133,7 @@ public class Locator
{
uri = uri.substring(1);
}
final String path = decodeUri(uri);
return path;
return decodeUri(uri);
}
/**
@@ -148,7 +147,7 @@ public class Locator
{
return uri;
}
final StringBuffer sb = new StringBuffer();
final StringBuilder sb = new StringBuilder();
final CharacterIterator iter = new StringCharacterIterator(uri);
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
{
@@ -171,8 +170,7 @@ public class Locator
sb.append(c);
}
}
final String path = sb.toString();
return path;
return sb.toString();
}
/**