Replaced instanceof L2PcInstance with isPlayer method.

This commit is contained in:
MobiusDev
2018-07-01 00:13:23 +00:00
parent 0259b6527c
commit 5934fac571
365 changed files with 828 additions and 835 deletions

View File

@@ -24,6 +24,7 @@ import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.xml.impl.AdminData;
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
import com.l2jmobius.gameserver.model.L2AccessLevel;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.Disconnection;
@@ -49,13 +50,14 @@ public final class AdminChangeAccessLevel implements IAdminCommandHandler
try
{
final int lvl = Integer.parseInt(parts[1]);
if (activeChar.getTarget() instanceof L2PcInstance)
final L2Object target = activeChar.getTarget();
if ((target == null) || !target.isPlayer())
{
onlineChange(activeChar, (L2PcInstance) activeChar.getTarget(), lvl);
activeChar.sendPacket(SystemMessageId.INVALID_TARGET);
}
else
{
activeChar.sendPacket(SystemMessageId.INVALID_TARGET);
onlineChange(activeChar, (L2PcInstance) target, lvl);
}
}
catch (Exception e)

View File

@@ -201,15 +201,12 @@ public class AdminClan implements IAdminCommandHandler
else
{
final L2Object targetObj = activeChar.getTarget();
if (targetObj instanceof L2PcInstance)
{
player = targetObj.getActingPlayer();
}
else
if ((targetObj == null) || !targetObj.isPlayer())
{
activeChar.sendPacket(SystemMessageId.INVALID_TARGET);
return null;
}
player = targetObj.getActingPlayer();
}
return player;
}

View File

@@ -22,6 +22,7 @@ import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
import com.l2jmobius.gameserver.handler.IItemHandler;
import com.l2jmobius.gameserver.handler.ItemHandler;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.items.L2Item;
@@ -123,12 +124,8 @@ public class AdminCreateItem implements IAdminCommandHandler
{
try
{
L2PcInstance target;
if (activeChar.getTarget() instanceof L2PcInstance)
{
target = (L2PcInstance) activeChar.getTarget();
}
else
final L2Object target = activeChar.getTarget();
if ((target == null) || !target.isPlayer())
{
BuilderUtil.sendSysMessage(activeChar, "Invalid target.");
return false;
@@ -142,13 +139,13 @@ public class AdminCreateItem implements IAdminCommandHandler
final int idval = Integer.parseInt(id);
final String num = st.nextToken();
final long numval = Long.parseLong(num);
createItem(activeChar, target, idval, numval);
createItem(activeChar, (L2PcInstance) target, idval, numval);
}
else if (st.countTokens() == 1)
{
final String id = st.nextToken();
final int idval = Integer.parseInt(id);
createItem(activeChar, target, idval, 1);
createItem(activeChar, (L2PcInstance) target, idval, 1);
}
}
catch (StringIndexOutOfBoundsException e)

View File

@@ -205,7 +205,7 @@ public class AdminCursedWeapons implements IAdminCommandHandler
else
{
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
((L2PcInstance) target).addItem("AdminCursedWeaponAdd", id, 1, target, true);
}

View File

@@ -53,7 +53,7 @@ public class AdminDisconnect implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}

View File

@@ -125,7 +125,7 @@ public class AdminEditChar implements IAdminCommandHandler
{
showCharacterInfo(activeChar, L2World.getInstance().getPlayer(data[1]));
}
else if (activeChar.getTarget() instanceof L2PcInstance)
else if ((activeChar.getTarget() != null) && activeChar.getTarget().isPlayer())
{
showCharacterInfo(activeChar, activeChar.getTarget().getActingPlayer());
}
@@ -198,7 +198,7 @@ public class AdminEditChar implements IAdminCommandHandler
{
editCharacter(activeChar, data[1]);
}
else if (activeChar.getTarget() instanceof L2PcInstance)
else if ((activeChar.getTarget() != null) && activeChar.getTarget().isPlayer())
{
editCharacter(activeChar, null);
}
@@ -274,7 +274,7 @@ public class AdminEditChar implements IAdminCommandHandler
final String val = command.substring(13);
final int pvp = Integer.parseInt(val);
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
final L2PcInstance player = (L2PcInstance) target;
player.setPvpKills(pvp);
@@ -304,7 +304,7 @@ public class AdminEditChar implements IAdminCommandHandler
final String val = command.substring(14);
final int fame = Integer.parseInt(val);
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
final L2PcInstance player = (L2PcInstance) target;
player.setFame(fame);
@@ -334,7 +334,7 @@ public class AdminEditChar implements IAdminCommandHandler
final String val = command.substring(10);
final int recVal = Integer.parseInt(val);
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
final L2PcInstance player = (L2PcInstance) target;
player.setRecomHave(recVal);
@@ -456,7 +456,7 @@ public class AdminEditChar implements IAdminCommandHandler
final String val = command.substring(15);
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -480,7 +480,7 @@ public class AdminEditChar implements IAdminCommandHandler
final String val = command.substring(17);
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -531,7 +531,7 @@ public class AdminEditChar implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -550,7 +550,7 @@ public class AdminEditChar implements IAdminCommandHandler
final String val = command.substring(15);
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -574,7 +574,7 @@ public class AdminEditChar implements IAdminCommandHandler
final String val = command.substring(16);
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -695,7 +695,7 @@ public class AdminEditChar implements IAdminCommandHandler
else
{
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
pl = (L2PcInstance) target;
}
@@ -832,7 +832,7 @@ public class AdminEditChar implements IAdminCommandHandler
target = activeChar.getTarget();
}
if (target instanceof L2PcInstance)
if (target.isPlayer())
{
if (((L2PcInstance) target).isInParty())
{
@@ -852,14 +852,14 @@ public class AdminEditChar implements IAdminCommandHandler
else if (command.equals("admin_setnoble"))
{
L2PcInstance player = null;
if (activeChar.getTarget() == null)
{
player = activeChar;
}
else if ((activeChar.getTarget() != null) && (activeChar.getTarget() instanceof L2PcInstance))
if ((activeChar.getTarget() != null) && (activeChar.getTarget().isPlayer()))
{
player = (L2PcInstance) activeChar.getTarget();
}
else
{
player = activeChar;
}
if (player != null)
{
@@ -1082,7 +1082,7 @@ public class AdminEditChar implements IAdminCommandHandler
if (player == null)
{
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -1214,7 +1214,7 @@ public class AdminEditChar implements IAdminCommandHandler
target = activeChar.getTarget();
}
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
final L2PcInstance player = (L2PcInstance) target;
gatherCharacterInfo(activeChar, player, "charedit.htm");

View File

@@ -119,7 +119,7 @@ public class AdminElement implements IAdminCommandHandler
target = activeChar;
}
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if (target.isPlayer())
{
player = (L2PcInstance) target;
}

View File

@@ -381,7 +381,7 @@ public class AdminEventEngine implements IAdminCommandHandler
}
}
}
else if ((activeChar.getTarget() != null) && (activeChar.getTarget() instanceof L2PcInstance))
else if ((activeChar.getTarget() != null) && (activeChar.getTarget().isPlayer()))
{
L2Event.removeAndResetPlayer((L2PcInstance) activeChar.getTarget());
}

View File

@@ -89,7 +89,7 @@ public class AdminExpSp implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -112,7 +112,7 @@ public class AdminExpSp implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -155,7 +155,7 @@ public class AdminExpSp implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}

View File

@@ -72,7 +72,7 @@ public class AdminFortSiege implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}

View File

@@ -78,7 +78,7 @@ public class AdminGmChat implements IAdminCommandHandler
activeChar.sendPacket(SystemMessageId.SELECT_TARGET);
return;
}
if (!(target instanceof L2PcInstance))
if (!target.isPlayer())
{
activeChar.sendPacket(SystemMessageId.INVALID_TARGET);
return;

View File

@@ -97,7 +97,7 @@ public class AdminHeal implements IAdminCommandHandler
L2World.getInstance().forEachVisibleObject(activeChar, L2Character.class, character ->
{
character.setCurrentHpMp(character.getMaxHp(), character.getMaxMp());
if (character instanceof L2PcInstance)
if (character.isPlayer())
{
character.setCurrentCp(character.getMaxCp());
}
@@ -119,7 +119,7 @@ public class AdminHeal implements IAdminCommandHandler
{
final L2Character target = (L2Character) obj;
target.setCurrentHpMp(target.getMaxHp(), target.getMaxMp());
if (target instanceof L2PcInstance)
if (target.isPlayer())
{
target.setCurrentCp(target.getMaxCp());
}

View File

@@ -95,7 +95,7 @@ public class AdminInstanceZone implements IAdminCommandHandler
}
else if (activeChar.getTarget() != null)
{
if (activeChar.getTarget() instanceof L2PcInstance)
if (activeChar.getTarget().isPlayer())
{
display((L2PcInstance) activeChar.getTarget(), activeChar);
}

View File

@@ -54,7 +54,7 @@ public class AdminInvul implements IAdminCommandHandler
else if (command.equals("admin_setinvul"))
{
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
handleInvul((L2PcInstance) target);
}

View File

@@ -125,7 +125,7 @@ public class AdminKill implements IAdminCommandHandler
private void kill(L2PcInstance activeChar, L2Character target)
{
if (target instanceof L2PcInstance)
if (target.isPlayer())
{
if (!target.isGM())
{

View File

@@ -66,7 +66,7 @@ public class AdminLevel implements IAdminCommandHandler
final int maxLevel = ExperienceData.getInstance().getMaxLevel();
try
{
if (!(targetChar instanceof L2PcInstance))
if ((targetChar == null) || !targetChar.isPlayer())
{
activeChar.sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET); // incorrect target!
return false;

View File

@@ -231,7 +231,7 @@ public class AdminMenu implements IAdminCommandHandler
}
if (target != null)
{
if (target instanceof L2PcInstance)
if (target.isPlayer())
{
target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar, null);
filename = "charmanage.htm";

View File

@@ -102,7 +102,7 @@ public class AdminPetition implements IAdminCommandHandler
try
{
final L2Object targetChar = activeChar.getTarget();
if ((targetChar == null) || !(targetChar instanceof L2PcInstance))
if ((targetChar == null) || !targetChar.isPlayer())
{
activeChar.sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
return false;

View File

@@ -52,7 +52,7 @@ public class AdminPledge implements IAdminCommandHandler
final StringTokenizer st = new StringTokenizer(command);
final String cmd = st.nextToken();
final L2Object target = activeChar.getTarget();
final L2PcInstance targetPlayer = target instanceof L2PcInstance ? (L2PcInstance) target : null;
final L2PcInstance targetPlayer = (target != null) && target.isPlayer() ? (L2PcInstance) target : null;
L2Clan clan = targetPlayer != null ? targetPlayer.getClan() : null;
if (targetPlayer == null)
{

View File

@@ -141,7 +141,7 @@ public class AdminRes implements IAdminCommandHandler
L2World.getInstance().forEachVisibleObjectInRange(activeChar, L2Character.class, radius, knownChar ->
{
if (!(knownChar instanceof L2PcInstance) && !(knownChar instanceof L2ControllableMobInstance))
if (!knownChar.isPlayer() && !(knownChar instanceof L2ControllableMobInstance))
{
doResurrect(knownChar);
}
@@ -156,7 +156,7 @@ public class AdminRes implements IAdminCommandHandler
return;
}
if ((obj instanceof L2PcInstance) || (obj instanceof L2ControllableMobInstance))
if ((obj == null) || (obj.isPlayer()) || (obj instanceof L2ControllableMobInstance))
{
activeChar.sendPacket(SystemMessageId.INVALID_TARGET);
return;
@@ -173,7 +173,7 @@ public class AdminRes implements IAdminCommandHandler
}
// If the target is a player, then restore the XP lost on death.
if (targetChar instanceof L2PcInstance)
if (targetChar.isPlayer())
{
((L2PcInstance) targetChar).restoreExp(100.0);
}

View File

@@ -131,7 +131,7 @@ public class AdminRide implements IAdminCommandHandler
{
L2PcInstance player = null;
if ((activeChar.getTarget() == null) || (activeChar.getTarget().getObjectId() == activeChar.getObjectId()) || !(activeChar.getTarget() instanceof L2PcInstance))
if ((activeChar.getTarget() == null) || (activeChar.getTarget().getObjectId() == activeChar.getObjectId()) || !activeChar.getTarget().isPlayer())
{
player = activeChar;
}

View File

@@ -295,7 +295,7 @@ public class AdminTeleport implements IAdminCommandHandler
else
{
final L2Object target = activeChar.getTarget();
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
teleportHome(target.getActingPlayer());
}
@@ -386,7 +386,7 @@ public class AdminTeleport implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}
@@ -406,7 +406,7 @@ public class AdminTeleport implements IAdminCommandHandler
{
final L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
if ((target != null) && target.isPlayer())
{
player = (L2PcInstance) target;
}

View File

@@ -56,7 +56,7 @@ public class AdminVitality implements IAdminCommandHandler
final StringTokenizer st = new StringTokenizer(command, " ");
final String cmd = st.nextToken();
if (activeChar.getTarget() instanceof L2PcInstance)
if ((activeChar.getTarget() != null) && activeChar.getTarget().isPlayer())
{
final L2PcInstance target = (L2PcInstance) activeChar.getTarget();

View File

@@ -53,7 +53,7 @@ public final class GiveRecommendation extends AbstractEffect
@Override
public void instant(L2Character effector, L2Character effected, Skill skill, L2ItemInstance item)
{
final L2PcInstance target = effected instanceof L2PcInstance ? (L2PcInstance) effected : null;
final L2PcInstance target = (effected != null) && effected.isPlayer() ? (L2PcInstance) effected : null;
if (target != null)
{
int recommendationsGiven = _amount;
@@ -74,7 +74,7 @@ public final class GiveRecommendation extends AbstractEffect
}
else
{
final L2PcInstance player = effector instanceof L2PcInstance ? (L2PcInstance) effector : null;
final L2PcInstance player = (effector != null) && effector.isPlayer() ? (L2PcInstance) effector : null;
if (player != null)
{
player.sendPacket(SystemMessageId.NOTHING_HAPPENED);

View File

@@ -31,7 +31,7 @@ public class Bypass implements IItemHandler
@Override
public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
{
if (!(playable instanceof L2PcInstance))
if (!playable.isPlayer())
{
return false;
}