L2JMobius

High Five "UpdateRelation" encapsulation

kinghanker · 1 · 2335

Offline kinghanker

  • Knight
  • ***
    • Posts: 64
Following this update(https://bitbucket.org/MobiusDev/l2j_mobius/commits/aaddd88a4f52a5cfc51dcc3073ad279ff99034ee)
I believe this encapsulation can be useful.

Code: [Select]
diff --git a/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 90e759f1ea42441d16b544d0348383981d31302c..b7cebbb7a98e4cd37880430ffdef6509e2f82413 100644
--- a/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -4155,18 +4155,7 @@ public class PlayerInstance extends Playable
 
  if (isCharInfo)
  {
- final int relation = getRelation(player);
- final boolean isAutoAttackable = isAutoAttackable(player);
- final RelationCache cache = getKnownRelations().get(player.getObjectId());
- if ((cache == null) || (cache.getRelation() != relation) || (cache.isAutoAttackable() != isAutoAttackable))
- {
- player.sendPacket(new RelationChanged(this, relation, isAutoAttackable));
- if (hasSummon())
- {
- player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable));
- }
- getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
- }
+ updateRelation(player);
  }
  });
  }
@@ -4191,18 +4180,7 @@ public class PlayerInstance extends Playable
 
  if (isCharInfo)
  {
- final int relation = getRelation(player);
- final boolean isAutoAttackable = isAutoAttackable(player);
- final RelationCache cache = getKnownRelations().get(player.getObjectId());
- if ((cache == null) || (cache.getRelation() != relation) || (cache.isAutoAttackable() != isAutoAttackable))
- {
- player.sendPacket(new RelationChanged(this, relation, isAutoAttackable));
- if (hasSummon())
- {
- player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable));
- }
- getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
- }
+ updateRelation(player);
  }
  });
  }
@@ -13015,18 +12993,8 @@ public class PlayerInstance extends Playable
  player.sendPacket(new ExBrExtraUserInfo(this));
  }
 
- final int relation = getRelation(player);
- final boolean isAutoAttackable = isAutoAttackable(player);
- final RelationCache cache = getKnownRelations().get(player.getObjectId());
- if ((cache == null) || (cache.getRelation() != relation) || (cache.isAutoAttackable() != isAutoAttackable))
- {
- player.sendPacket(new RelationChanged(this, relation, isAutoAttackable));
- if (hasSummon())
- {
- player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable));
- }
- getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
- }
+ updateRelation(player);
+ player.updateRelation(this);
 
  switch (_privateStoreType)
  {
@@ -14526,4 +14494,20 @@ public class PlayerInstance extends Playable
 
  return val;
  }
+
+ public void updateRelation(PlayerInstance player)
+ {
+ final int relation = getRelation(player);
+ final boolean isAutoAttackable = isAutoAttackable(player);
+ final RelationCache oldrelation = getKnownRelations().get(player.getObjectId());
+ if ((oldrelation == null) || (oldrelation.getRelation() != relation) || (oldrelation.isAutoAttackable() != isAutoAttackable))
+ {
+ player.sendPacket(new RelationChanged(this, relation, isAutoAttackable));
+ if (hasSummon())
+ {
+ player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable));
+ }
+ getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
+ }
+ }
 }