Fixed class change NPE.

This commit is contained in:
MobiusDev
2018-04-07 18:10:37 +00:00
parent ecfee7dd5f
commit 4b01a96675
7 changed files with 48 additions and 27 deletions
@@ -9627,6 +9627,13 @@ public final class L2PcInstance extends L2Playable
try try
{ {
// Notify to scripts before class is removed.
if (!getSubClasses().isEmpty()) // also null check
{
final int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
}
final SubClass subClass = getSubClasses().remove(classIndex); final SubClass subClass = getSubClasses().remove(classIndex);
if (subClass == null) if (subClass == null)
{ {
@@ -9686,10 +9693,6 @@ public final class L2PcInstance extends L2Playable
_log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e); _log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e);
return false; return false;
} }
// Notify to scripts
int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
} }
finally finally
{ {
@@ -9634,6 +9634,13 @@ public final class L2PcInstance extends L2Playable
try try
{ {
// Notify to scripts before class is removed.
if (!getSubClasses().isEmpty()) // also null check
{
final int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
}
final SubClass subClass = getSubClasses().remove(classIndex); final SubClass subClass = getSubClasses().remove(classIndex);
if (subClass == null) if (subClass == null)
{ {
@@ -9693,10 +9700,6 @@ public final class L2PcInstance extends L2Playable
_log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e); _log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e);
return false; return false;
} }
// Notify to scripts
int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
} }
finally finally
{ {
@@ -9644,6 +9644,13 @@ public final class L2PcInstance extends L2Playable
try try
{ {
// Notify to scripts before class is removed.
if (!getSubClasses().isEmpty()) // also null check
{
final int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
}
final SubClass subClass = getSubClasses().remove(classIndex); final SubClass subClass = getSubClasses().remove(classIndex);
if (subClass == null) if (subClass == null)
{ {
@@ -9703,10 +9710,6 @@ public final class L2PcInstance extends L2Playable
_log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e); _log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e);
return false; return false;
} }
// Notify to scripts
int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
} }
finally finally
{ {
@@ -9637,6 +9637,13 @@ public final class L2PcInstance extends L2Playable
try try
{ {
// Notify to scripts before class is removed.
if (!getSubClasses().isEmpty()) // also null check
{
final int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
}
final SubClass subClass = getSubClasses().remove(classIndex); final SubClass subClass = getSubClasses().remove(classIndex);
if (subClass == null) if (subClass == null)
{ {
@@ -9696,10 +9703,6 @@ public final class L2PcInstance extends L2Playable
_log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e); _log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e);
return false; return false;
} }
// Notify to scripts
int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
} }
finally finally
{ {
@@ -10092,9 +10092,12 @@ public final class L2PcInstance extends L2Playable
return false; return false;
} }
// Notify to scripts // Notify to scripts before class is removed.
int classId = getSubClasses().get(classIndex).getClassId(); if (!getSubClasses().isEmpty()) // also null check
{
final int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this); EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
}
getSubClasses().remove(classIndex); getSubClasses().remove(classIndex);
} }
@@ -9569,6 +9569,13 @@ public final class L2PcInstance extends L2Playable
try try
{ {
// Notify to scripts before class is removed.
if (!getSubClasses().isEmpty()) // also null check
{
final int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
}
final SubClass subClass = getSubClasses().remove(classIndex); final SubClass subClass = getSubClasses().remove(classIndex);
if (subClass == null) if (subClass == null)
{ {
@@ -9628,10 +9635,6 @@ public final class L2PcInstance extends L2Playable
_log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e); _log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e);
return false; return false;
} }
// Notify to scripts
int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
} }
finally finally
{ {
@@ -9569,6 +9569,13 @@ public final class L2PcInstance extends L2Playable
try try
{ {
// Notify to scripts before class is removed.
if (!getSubClasses().isEmpty()) // also null check
{
final int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
}
final SubClass subClass = getSubClasses().remove(classIndex); final SubClass subClass = getSubClasses().remove(classIndex);
if (subClass == null) if (subClass == null)
{ {
@@ -9628,10 +9635,6 @@ public final class L2PcInstance extends L2Playable
_log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e); _log.log(Level.WARNING, "Could not modify sub class for " + getName() + " to class index " + classIndex + ": " + e.getMessage(), e);
return false; return false;
} }
// Notify to scripts
int classId = getSubClasses().get(classIndex).getClassId();
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerProfessionCancel(this, classId), this);
} }
finally finally
{ {