Code improvements.
This commit is contained in:
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.l2jmobius.gameserver.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -50,8 +49,7 @@ public final class Broadcast
|
||||
*/
|
||||
public static void toPlayersTargettingMyself(L2Character character, L2GameServerPacket mov)
|
||||
{
|
||||
final Collection<L2PcInstance> plrs = character.getKnownList().getKnownPlayers().values();
|
||||
for (L2PcInstance player : plrs)
|
||||
for (L2PcInstance player : character.getKnownList().getKnownPlayers().values())
|
||||
{
|
||||
if (player.getTarget() != character)
|
||||
{
|
||||
@ -73,8 +71,7 @@ public final class Broadcast
|
||||
*/
|
||||
public static void toKnownPlayers(L2Character character, L2GameServerPacket mov)
|
||||
{
|
||||
final Collection<L2PcInstance> plrs = character.getKnownList().getKnownPlayers().values();
|
||||
for (L2PcInstance player : plrs)
|
||||
for (L2PcInstance player : character.getKnownList().getKnownPlayers().values())
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
@ -132,8 +129,7 @@ public final class Broadcast
|
||||
radius = 1500;
|
||||
}
|
||||
|
||||
final Collection<L2PcInstance> plrs = character.getKnownList().getKnownPlayers().values();
|
||||
for (L2PcInstance player : plrs)
|
||||
for (L2PcInstance player : character.getKnownList().getKnownPlayers().values())
|
||||
{
|
||||
if (character.isInsideRadius(player, radius, false, false))
|
||||
{
|
||||
@ -173,8 +169,7 @@ public final class Broadcast
|
||||
character.sendPacket(mov);
|
||||
}
|
||||
|
||||
final Collection<L2PcInstance> plrs = character.getKnownList().getKnownPlayers().values();
|
||||
for (L2PcInstance player : plrs)
|
||||
for (L2PcInstance player : character.getKnownList().getKnownPlayers().values())
|
||||
{
|
||||
if ((player != null) && Util.checkIfInRange(radius, character, player, false))
|
||||
{
|
||||
|
@ -173,12 +173,7 @@ public final class Evolve
|
||||
return false;
|
||||
}
|
||||
|
||||
int oldpetlvl = item.getEnchantLevel();
|
||||
if (oldpetlvl < petminlvl)
|
||||
{
|
||||
oldpetlvl = petminlvl;
|
||||
}
|
||||
|
||||
final int oldpetlvl = item.getEnchantLevel() < petminlvl ? petminlvl : item.getEnchantLevel();
|
||||
final L2PetData oldData = PetDataTable.getInstance().getPetDataByItemId(itemIdtake);
|
||||
if (oldData == null)
|
||||
{
|
||||
|
@ -122,12 +122,9 @@ public final class FloodProtectorAction
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_count.get() > 0)
|
||||
if ((_count.get() > 0) && _config.LOG_FLOODING && _log.isLoggable(Level.WARNING))
|
||||
{
|
||||
if (_config.LOG_FLOODING && _log.isLoggable(Level.WARNING))
|
||||
{
|
||||
log(" issued ", String.valueOf(_count), " extra requests within ~", String.valueOf(_config.FLOOD_PROTECTION_INTERVAL * GameTimeController.MILLIS_IN_TICK), " ms");
|
||||
}
|
||||
log(" issued ", String.valueOf(_count), " extra requests within ~", String.valueOf(_config.FLOOD_PROTECTION_INTERVAL * GameTimeController.MILLIS_IN_TICK), " ms");
|
||||
}
|
||||
|
||||
_nextGameTick = curTick + _config.FLOOD_PROTECTION_INTERVAL;
|
||||
@ -173,18 +170,20 @@ public final class FloodProtectorAction
|
||||
*/
|
||||
private void jailChar()
|
||||
{
|
||||
if (_client.getActiveChar() != null)
|
||||
if (_client.getActiveChar() == null)
|
||||
{
|
||||
final int charId = _client.getActiveChar().getObjectId();
|
||||
if (charId > 0)
|
||||
{
|
||||
PunishmentManager.getInstance().startPunishment(new PunishmentTask(charId, PunishmentAffect.CHARACTER, PunishmentType.JAIL, System.currentTimeMillis() + _config.PUNISHMENT_TIME, "", getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
if (_log.isLoggable(Level.WARNING))
|
||||
{
|
||||
log(" jailed for flooding ", _config.PUNISHMENT_TIME <= 0 ? "forever" : "for " + (_config.PUNISHMENT_TIME / 60000) + " mins");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final int charId = _client.getActiveChar().getObjectId();
|
||||
if (charId > 0)
|
||||
{
|
||||
PunishmentManager.getInstance().startPunishment(new PunishmentTask(charId, PunishmentAffect.CHARACTER, PunishmentType.JAIL, System.currentTimeMillis() + _config.PUNISHMENT_TIME, "", getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
if (_log.isLoggable(Level.WARNING))
|
||||
{
|
||||
log(" jailed for flooding ", _config.PUNISHMENT_TIME <= 0 ? "forever" : "for " + (_config.PUNISHMENT_TIME / 60000) + " mins");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,10 +43,7 @@ public final class GeoUtils
|
||||
|
||||
while (iter.next())
|
||||
{
|
||||
final int wx = GeoData.getInstance().getWorldX(iter.x());
|
||||
final int wy = GeoData.getInstance().getWorldY(iter.y());
|
||||
|
||||
prim.addPoint(Color.RED, wx, wy, z);
|
||||
prim.addPoint(Color.RED, GeoData.getInstance().getWorldX(iter.x()), GeoData.getInstance().getWorldY(iter.y()), z);
|
||||
}
|
||||
player.sendPacket(prim);
|
||||
}
|
||||
@ -93,11 +90,7 @@ public final class GeoUtils
|
||||
|
||||
private static Color getDirectionColor(int x, int y, int z, int nswe)
|
||||
{
|
||||
if (GeoData.getInstance().checkNearestNswe(x, y, z, nswe))
|
||||
{
|
||||
return Color.GREEN;
|
||||
}
|
||||
return Color.RED;
|
||||
return GeoData.getInstance().checkNearestNswe(x, y, z, nswe) ? Color.GREEN : Color.RED;
|
||||
}
|
||||
|
||||
public static void debugGrid(L2PcInstance player)
|
||||
|
@ -220,12 +220,7 @@ public class HtmlUtil
|
||||
page = pages - 1;
|
||||
}
|
||||
|
||||
int start = 0;
|
||||
if (page > 0)
|
||||
{
|
||||
start = elementsPerPage * page;
|
||||
}
|
||||
|
||||
final int start = page > 0 ? elementsPerPage * page : 0;
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
int i = 0;
|
||||
for (T element : elements)
|
||||
|
@ -65,7 +65,7 @@ public final class LinePointIterator
|
||||
_first = false;
|
||||
return true;
|
||||
}
|
||||
else if (_dx >= _dy)
|
||||
if (_dx >= _dy)
|
||||
{
|
||||
if (_srcX != _dstX)
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ public final class LinePointIterator3D
|
||||
_first = false;
|
||||
return true;
|
||||
}
|
||||
else if ((_dx >= _dy) && (_dx >= _dz))
|
||||
if ((_dx >= _dy) && (_dx >= _dz))
|
||||
{
|
||||
if (_srcX != _dstX)
|
||||
{
|
||||
|
@ -83,13 +83,7 @@ public class MinionList
|
||||
*/
|
||||
public final void spawnMinions(List<MinionHolder> minions)
|
||||
{
|
||||
if (_master.isAlikeDead())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// List<MinionHolder> minions = _master.getTemplate().getParameters().getMinionList("Privates");
|
||||
if (minions == null)
|
||||
if (_master.isAlikeDead() || (minions == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -119,22 +113,23 @@ public class MinionList
|
||||
*/
|
||||
public void deleteSpawnedMinions()
|
||||
{
|
||||
if (!_minionReferences.isEmpty())
|
||||
if (_minionReferences.isEmpty())
|
||||
{
|
||||
for (L2MonsterInstance minion : _minionReferences)
|
||||
return;
|
||||
}
|
||||
for (L2MonsterInstance minion : _minionReferences)
|
||||
{
|
||||
if (minion != null)
|
||||
{
|
||||
if (minion != null)
|
||||
minion.setLeader(null);
|
||||
minion.deleteMe();
|
||||
if (_reusedMinionReferences != null)
|
||||
{
|
||||
minion.setLeader(null);
|
||||
minion.deleteMe();
|
||||
if (_reusedMinionReferences != null)
|
||||
{
|
||||
_reusedMinionReferences.add(minion);
|
||||
}
|
||||
_reusedMinionReferences.add(minion);
|
||||
}
|
||||
}
|
||||
_minionReferences.clear();
|
||||
}
|
||||
_minionReferences.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,22 +249,8 @@ public class MinionList
|
||||
int newX = Rnd.get(minRadius * 2, offset * 2); // x
|
||||
int newY = Rnd.get(newX, offset * 2); // distance
|
||||
newY = (int) Math.sqrt((newY * newY) - (newX * newX)); // y
|
||||
if (newX > (offset + minRadius))
|
||||
{
|
||||
newX = (_master.getX() + newX) - offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
newX = (_master.getX() - newX) + minRadius;
|
||||
}
|
||||
if (newY > (offset + minRadius))
|
||||
{
|
||||
newY = (_master.getY() + newY) - offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
newY = (_master.getY() - newY) + minRadius;
|
||||
}
|
||||
newX = newX > (offset + minRadius) ? (_master.getX() + newX) - offset : (_master.getX() - newX) + minRadius;
|
||||
newY = newY > (offset + minRadius) ? (_master.getY() + newY) - offset : (_master.getY() - newY) + minRadius;
|
||||
|
||||
minion.teleToLocation(new Location(newX, newY, _master.getZ()));
|
||||
}
|
||||
@ -312,20 +293,18 @@ public class MinionList
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!_master.isAlikeDead() && _master.isVisible())
|
||||
if (_master.isAlikeDead() || !_master.isVisible() || _minion.isVisible())
|
||||
{
|
||||
// minion can be already spawned or deleted
|
||||
if (!_minion.isVisible())
|
||||
{
|
||||
if (_reusedMinionReferences != null)
|
||||
{
|
||||
_reusedMinionReferences.remove(_minion);
|
||||
}
|
||||
|
||||
_minion.refreshID();
|
||||
initializeNpcInstance(_master, _minion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_reusedMinionReferences != null)
|
||||
{
|
||||
_reusedMinionReferences.remove(_minion);
|
||||
}
|
||||
|
||||
_minion.refreshID();
|
||||
initializeNpcInstance(_master, _minion);
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,11 +327,7 @@ public class MinionList
|
||||
{
|
||||
// Get the template of the Minion to spawn
|
||||
final L2NpcTemplate minionTemplate = NpcData.getInstance().getTemplate(minionId);
|
||||
if (minionTemplate == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return initializeNpcInstance(master, new L2MonsterInstance(minionTemplate));
|
||||
return minionTemplate == null ? null : initializeNpcInstance(master, new L2MonsterInstance(minionTemplate));
|
||||
}
|
||||
|
||||
protected static final L2MonsterInstance initializeNpcInstance(L2MonsterInstance master, L2MonsterInstance minion)
|
||||
@ -378,22 +353,8 @@ public class MinionList
|
||||
int newX = Rnd.get(minRadius * 2, offset * 2); // x
|
||||
int newY = Rnd.get(newX, offset * 2); // distance
|
||||
newY = (int) Math.sqrt((newY * newY) - (newX * newX)); // y
|
||||
if (newX > (offset + minRadius))
|
||||
{
|
||||
newX = (master.getX() + newX) - offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
newX = (master.getX() - newX) + minRadius;
|
||||
}
|
||||
if (newY > (offset + minRadius))
|
||||
{
|
||||
newY = (master.getY() + newY) - offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
newY = (master.getY() - newY) + minRadius;
|
||||
}
|
||||
newX = newX > (offset + minRadius) ? (master.getX() + newX) - offset : (master.getX() - newX) + minRadius;
|
||||
newY = newY > (offset + minRadius) ? (master.getY() + newY) - offset : (master.getY() - newY) + minRadius;
|
||||
|
||||
minion.spawnMe(newX, newY, master.getZ());
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.l2jmobius.gameserver.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
@ -92,8 +91,7 @@ public final class Util
|
||||
|
||||
public static final double convertHeadingToDegree(int clientHeading)
|
||||
{
|
||||
final double degree = clientHeading / 182.044444444;
|
||||
return degree;
|
||||
return clientHeading / 182.044444444;
|
||||
}
|
||||
|
||||
public static final int convertDegreeToClientHeading(double degree)
|
||||
@ -223,11 +221,7 @@ public final class Util
|
||||
*/
|
||||
public static boolean checkIfInRange(int range, L2Object obj1, L2Object obj2, boolean includeZAxis)
|
||||
{
|
||||
if ((obj1 == null) || (obj2 == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (obj1.getInstanceId() != obj2.getInstanceId())
|
||||
if ((obj1 == null) || (obj2 == null) || (obj1.getInstanceId() != obj2.getInstanceId()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -236,11 +230,7 @@ public final class Util
|
||||
return true; // not limited
|
||||
}
|
||||
|
||||
int rad = 0;
|
||||
if (obj1 instanceof L2Character)
|
||||
{
|
||||
rad += ((L2Character) obj1).getTemplate().getCollisionRadius();
|
||||
}
|
||||
int rad = obj1 instanceof L2Character ? 0 + ((L2Character) obj1).getTemplate().getCollisionRadius() : 0;
|
||||
if (obj2 instanceof L2Character)
|
||||
{
|
||||
rad += ((L2Character) obj2).getTemplate().getCollisionRadius();
|
||||
@ -280,12 +270,12 @@ public final class Util
|
||||
final int dx = obj1.getX() - obj2.getX();
|
||||
final int dy = obj1.getY() - obj2.getY();
|
||||
|
||||
if (includeZAxis)
|
||||
if (!includeZAxis)
|
||||
{
|
||||
final int dz = obj1.getZ() - obj2.getZ();
|
||||
return ((dx * dx) + (dy * dy) + (dz * dz)) <= (radius * radius);
|
||||
return ((dx * dx) + (dy * dy)) <= (radius * radius);
|
||||
}
|
||||
return ((dx * dx) + (dy * dy)) <= (radius * radius);
|
||||
final int dz = obj1.getZ() - obj2.getZ();
|
||||
return ((dx * dx) + (dy * dy) + (dz * dz)) <= (radius * radius);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -409,8 +399,7 @@ public final class Util
|
||||
*/
|
||||
public static String formatDouble(double val, String format)
|
||||
{
|
||||
final DecimalFormat formatter = new DecimalFormat(format, new DecimalFormatSymbols(Locale.ENGLISH));
|
||||
return formatter.format(val);
|
||||
return (new DecimalFormat(format, new DecimalFormatSymbols(Locale.ENGLISH))).format(val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -421,12 +410,7 @@ public final class Util
|
||||
*/
|
||||
public static String formatDate(Date date, String format)
|
||||
{
|
||||
if (date == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final DateFormat dateFormat = new SimpleDateFormat(format);
|
||||
return dateFormat.format(date);
|
||||
return date == null ? null : (new SimpleDateFormat(format)).format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -467,17 +451,12 @@ public final class Util
|
||||
public static File[] getDatapackFiles(String dirname, String extention)
|
||||
{
|
||||
final File dir = new File(Config.DATAPACK_ROOT, "/" + dirname);
|
||||
if (!dir.exists())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return dir.listFiles(new ExtFilter(extention));
|
||||
return !dir.exists() ? null : dir.listFiles(new ExtFilter(extention));
|
||||
}
|
||||
|
||||
public static String getDateString(Date date)
|
||||
{
|
||||
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return dateFormat.format(date.getTime());
|
||||
return (new SimpleDateFormat("yyyy-MM-dd")).format(date.getTime());
|
||||
}
|
||||
|
||||
private static final void buildHtmlBypassCache(L2PcInstance player, HtmlActionScope scope, String html)
|
||||
@ -496,16 +475,7 @@ public final class Util
|
||||
}
|
||||
|
||||
final int hParamPos = htmlLower.indexOf("-h ", bypassStartEnd);
|
||||
String bypass;
|
||||
if ((hParamPos != -1) && (hParamPos < bypassEnd))
|
||||
{
|
||||
bypass = html.substring(hParamPos + 3, bypassEnd).trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
bypass = html.substring(bypassStartEnd, bypassEnd).trim();
|
||||
}
|
||||
|
||||
String bypass = (hParamPos != -1) && (hParamPos < bypassEnd) ? html.substring(hParamPos + 3, bypassEnd).trim() : html.substring(bypassStartEnd, bypassEnd).trim();
|
||||
final int firstParameterStart = bypass.indexOf(AbstractHtmlPacket.VAR_PARAM_START_CHAR);
|
||||
if (firstParameterStart != -1)
|
||||
{
|
||||
@ -744,17 +714,7 @@ public final class Util
|
||||
public static boolean isInsideRangeOfObjectId(L2Object obj, int targetObjId, int radius)
|
||||
{
|
||||
final L2Object target = obj.getKnownList().getKnownObjects().get(targetObjId);
|
||||
if (target == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj.calculateDistance(target, false, false) > radius)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return (target != null) && (obj.calculateDistance(target, false, false) <= radius);
|
||||
}
|
||||
|
||||
public static int min(int value1, int value2, int... values)
|
||||
@ -1007,8 +967,7 @@ public final class Util
|
||||
{
|
||||
try
|
||||
{
|
||||
final String value = st.nextToken().trim();
|
||||
return Integer.parseInt(value);
|
||||
return Integer.parseInt(st.nextToken().trim());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user