From 4628bd3d86aac71b6d80b4db8ad0edd8698f6d5b Mon Sep 17 00:00:00 2001 From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com> Date: Wed, 26 Oct 2016 18:06:12 +0000 Subject: [PATCH] Partial sync latest Test changes to HighFive. --- .../instancemanager/MailManager.java | 6 +- .../gameserver/model/AutoSpawnHandler.java | 12 +-- .../model/actor/instance/L2PcInstance.java | 5 -- .../model/actor/knownlist/CharKnownList.java | 6 +- .../actor/knownlist/ObjectKnownList.java | 4 +- .../gameserver/model/actor/stat/PcStat.java | 2 +- .../gameserver/model/entity/Siegable.java | 3 +- .../entity/clanhall/ClanHallSiegeEngine.java | 15 +++- .../serverpackets/ExEnchantSkillList.java | 35 +++------ .../com/l2jmobius/gameserver/util/Util.java | 74 ++++--------------- 10 files changed, 54 insertions(+), 108 deletions(-) diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/MailManager.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/MailManager.java index fa94df90db..aa881e3804 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/MailManager.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/MailManager.java @@ -21,8 +21,8 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -138,7 +138,7 @@ public final class MailManager public final List getInbox(int objectId) { - final List inbox = new ArrayList<>(); + final List inbox = new LinkedList<>(); for (Message msg : getMessages()) { if ((msg != null) && (msg.getReceiverId() == objectId) && !msg.isDeletedByReceiver()) @@ -151,7 +151,7 @@ public final class MailManager public final List getOutbox(int objectId) { - final List outbox = new ArrayList<>(); + final List outbox = new LinkedList<>(); for (Message msg : getMessages()) { if ((msg != null) && (msg.getSenderId() == objectId) && !msg.isDeletedBySender()) diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/AutoSpawnHandler.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/AutoSpawnHandler.java index 9c16e74837..66c4b8e4a1 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/AutoSpawnHandler.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/AutoSpawnHandler.java @@ -20,7 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; -import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -32,6 +32,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import com.l2jmobius.commons.database.DatabaseFactory; import com.l2jmobius.gameserver.ThreadPoolManager; @@ -645,14 +646,9 @@ public class AutoSpawnHandler return _npcList; } - public List getSpawns() + public Collection getSpawns() { - final List npcSpawns = new ArrayList<>(); - for (L2Npc npcInst : _npcList) - { - npcSpawns.add(npcInst.getSpawn()); - } - return npcSpawns; + return _npcList.stream().map(L2Npc::getSpawn).collect(Collectors.toList()); } public void setSpawnCount(int spawnCount) diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java index 9514776d48..1de7502fa5 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java @@ -10744,11 +10744,6 @@ public final class L2PcInstance extends L2Playable return _lastServerPosition; } - public int getLastServerDistance(int x, int y, int z) - { - return (int) Util.calculateDistance(x, y, z, _lastServerPosition.getX(), _lastServerPosition.getY(), _lastServerPosition.getZ(), true, false); - } - @Override public void addExpAndSp(long addToExp, int addToSp) { diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java index ecf510d615..d36dfbbb7a 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java @@ -131,7 +131,7 @@ public class CharKnownList extends ObjectKnownList { pIter.remove(); } - else if (!player.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(player), getActiveObject(), player, true)) + else if (!player.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(player), getActiveObject(), player, true)) { pIter.remove(); removeKnownObject(player, true); @@ -152,7 +152,7 @@ public class CharKnownList extends ObjectKnownList { continue; } - else if (!summon.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(summon), getActiveObject(), summon, true)) + else if (!summon.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(summon), getActiveObject(), summon, true)) { sIter.remove(); removeKnownObject(summon, true); @@ -171,7 +171,7 @@ public class CharKnownList extends ObjectKnownList { oIter.remove(); } - else if (!object.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(object), getActiveObject(), object, true)) + else if (!object.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(object), getActiveObject(), object, true)) { oIter.remove(); removeKnownObject(object, true); diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java index 78cd50799c..0bf47f4507 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java @@ -61,7 +61,7 @@ public class ObjectKnownList } // Check if object is not inside distance to watch object - if (!Util.checkIfInShortRadius(getDistanceToWatchObject(object), getActiveObject(), object, true)) + if (!Util.checkIfInShortRange(getDistanceToWatchObject(object), getActiveObject(), object, true)) { return false; } @@ -169,7 +169,7 @@ public class ObjectKnownList } // Remove all objects invisible or too far - if (!object.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(object), getActiveObject(), object, true)) + if (!object.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(object), getActiveObject(), object, true)) { oIter.remove(); removeKnownObject(object, true); diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/stat/PcStat.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/stat/PcStat.java index 44291e02e3..45fc517d95 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/stat/PcStat.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/stat/PcStat.java @@ -157,7 +157,7 @@ public class PcStat extends PlayableStat float ratioTakenByPlayer = 0; // if this player has a pet and it is in his range he takes from the owner's Exp, give the pet Exp now - if (activeChar.hasPet() && Util.checkIfInShortRadius(Config.ALT_PARTY_RANGE, activeChar, activeChar.getSummon(), false)) + if (activeChar.hasPet() && Util.checkIfInShortRange(Config.ALT_PARTY_RANGE, activeChar, activeChar.getSummon(), false)) { final L2PetInstance pet = (L2PetInstance) activeChar.getSummon(); ratioTakenByPlayer = pet.getPetLevelData().getOwnerExpTaken() / 100f; diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/Siegable.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/Siegable.java index 49e78a2b00..a7c30eab14 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/Siegable.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/Siegable.java @@ -17,6 +17,7 @@ package com.l2jmobius.gameserver.model.entity; import java.util.Calendar; +import java.util.Collection; import java.util.List; import com.l2jmobius.gameserver.model.L2Clan; @@ -37,7 +38,7 @@ public interface Siegable L2SiegeClan getAttackerClan(L2Clan clan); - List getAttackerClans(); + Collection getAttackerClans(); List getAttackersInZone(); diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/clanhall/ClanHallSiegeEngine.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/clanhall/ClanHallSiegeEngine.java index 9c61f848ae..fbc302997d 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/clanhall/ClanHallSiegeEngine.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/entity/clanhall/ClanHallSiegeEngine.java @@ -21,6 +21,8 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -70,7 +72,7 @@ public abstract class ClanHallSiegeEngine extends Quest implements Siegable protected final Logger _log; private final Map _attackers = new ConcurrentHashMap<>(); - private List _guards; + private Collection _guards; public SiegableHall _hall; public ScheduledFuture _siegeTask; @@ -212,7 +214,12 @@ public abstract class ClanHallSiegeEngine extends Quest implements Siegable @Override public boolean checkIsAttacker(L2Clan clan) { - return (clan != null) && _attackers.containsKey(clan.getId()); + if (clan == null) + { + return false; + } + + return _attackers.containsKey(clan.getId()); } @Override @@ -234,9 +241,9 @@ public abstract class ClanHallSiegeEngine extends Quest implements Siegable } @Override - public List getAttackerClans() + public Collection getAttackerClans() { - return new ArrayList<>(_attackers.values()); + return Collections.unmodifiableCollection(_attackers.values()); } @Override diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/network/serverpackets/ExEnchantSkillList.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/network/serverpackets/ExEnchantSkillList.java index 86fb767811..26eb78f171 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/network/serverpackets/ExEnchantSkillList.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/network/serverpackets/ExEnchantSkillList.java @@ -16,9 +16,11 @@ */ package com.l2jmobius.gameserver.network.serverpackets; -import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; +import com.l2jmobius.gameserver.model.skills.Skill; + public class ExEnchantSkillList extends L2GameServerPacket { public enum EnchantSkillType @@ -30,29 +32,16 @@ public class ExEnchantSkillList extends L2GameServerPacket } private final EnchantSkillType _type; - private final List _skills; - - static class Skill - { - public int id; - public int nextLevel; - - Skill(int pId, int pNextLevel) - { - id = pId; - nextLevel = pNextLevel; - } - } - - public void addSkill(int id, int level) - { - _skills.add(new Skill(id, level)); - } + private final List _skills = new LinkedList<>(); public ExEnchantSkillList(EnchantSkillType type) { _type = type; - _skills = new ArrayList<>(); + } + + public void addSkill(Skill skill) + { + _skills.add(skill); } @Override @@ -63,10 +52,10 @@ public class ExEnchantSkillList extends L2GameServerPacket writeD(_type.ordinal()); writeD(_skills.size()); - for (Skill sk : _skills) + for (Skill skill : _skills) { - writeD(sk.id); - writeD(sk.nextLevel); + writeD(skill.getId()); + writeD(skill.getLevel()); } } } \ No newline at end of file diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/util/Util.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/util/Util.java index fcec30e3c9..f85b5a757d 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/util/Util.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/util/Util.java @@ -179,39 +179,6 @@ public final class Util return new String(arr); } - /** - * (Based on ucwords() function of PHP)
- * DrHouse: still functional but must be rewritten to avoid += to concat strings - * @param str - the string to capitalize - * @return a string with the first letter of every word in {@code str} capitalized - */ - @Deprecated - public static String capitalizeWords(String str) - { - if ((str == null) || str.isEmpty()) - { - return str; - } - - final char[] charArray = str.toCharArray(); - final StringBuilder result = new StringBuilder(); - - // Capitalize the first letter in the given string! - charArray[0] = Character.toUpperCase(charArray[0]); - - for (int i = 0; i < charArray.length; i++) - { - if (Character.isWhitespace(charArray[i])) - { - charArray[i + 1] = Character.toUpperCase(charArray[i + 1]); - } - - result.append(charArray[i]); - } - - return result.toString(); - } - /** * @param range * @param obj1 @@ -221,7 +188,11 @@ public final class Util */ public static boolean checkIfInRange(int range, L2Object obj1, L2Object obj2, boolean includeZAxis) { - if ((obj1 == null) || (obj2 == null) || (obj1.getInstanceId() != obj2.getInstanceId())) + if ((obj1 == null) || (obj2 == null)) + { + return false; + } + if (obj1.getInstanceId() != obj2.getInstanceId()) { return false; } @@ -230,52 +201,39 @@ public final class Util return true; // not limited } - int rad = obj1 instanceof L2Character ? 0 + ((L2Character) obj1).getTemplate().getCollisionRadius() : 0; + int radius = 0; + if (obj1 instanceof L2Character) + { + radius += ((L2Character) obj1).getTemplate().getCollisionRadius(); + } if (obj2 instanceof L2Character) { - rad += ((L2Character) obj2).getTemplate().getCollisionRadius(); + radius += ((L2Character) obj2).getTemplate().getCollisionRadius(); } - final double dx = obj1.getX() - obj2.getX(); - final double dy = obj1.getY() - obj2.getY(); - double d = (dx * dx) + (dy * dy); - - if (includeZAxis) - { - final double dz = obj1.getZ() - obj2.getZ(); - d += dz * dz; - } - return d <= ((range * range) + (2 * range * rad) + (rad * rad)); + return calculateDistance(obj1, obj2, includeZAxis, false) <= (range + radius); } /** * Checks if object is within short (sqrt(int.max_value)) radius, not using collisionRadius. Faster calculation than checkIfInRange if distance is short and collisionRadius isn't needed. Not for long distance checks (potential teleports, far away castles etc). - * @param radius + * @param range * @param obj1 * @param obj2 * @param includeZAxis if true, check also Z axis (3-dimensional check), otherwise only 2D * @return {@code true} if objects are within specified range between each other, {@code false} otherwise */ - public static boolean checkIfInShortRadius(int radius, L2Object obj1, L2Object obj2, boolean includeZAxis) + public static boolean checkIfInShortRange(int range, L2Object obj1, L2Object obj2, boolean includeZAxis) { if ((obj1 == null) || (obj2 == null)) { return false; } - if (radius == -1) + if (range == -1) { return true; // not limited } - final int dx = obj1.getX() - obj2.getX(); - final int dy = obj1.getY() - obj2.getY(); - - if (!includeZAxis) - { - return ((dx * dx) + (dy * dy)) <= (radius * radius); - } - final int dz = obj1.getZ() - obj2.getZ(); - return ((dx * dx) + (dy * dy) + (dz * dz)) <= (radius * radius); + return calculateDistance(obj1, obj2, includeZAxis, false) <= range; } /**