Added instance world support for StatsSet parameters.
This commit is contained in:
@@ -64,14 +64,8 @@ public class HallOfErosionAttack extends AbstractNpcAI
|
||||
tumorCount += value;
|
||||
}
|
||||
|
||||
public synchronized void addTag(int value)
|
||||
{
|
||||
tag += value;
|
||||
}
|
||||
|
||||
public HEAWorld()
|
||||
{
|
||||
tag = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +532,8 @@ public class HallOfErosionAttack extends AbstractNpcAI
|
||||
|
||||
if (npc.getId() == TUMOR_DEAD)
|
||||
{
|
||||
world.addTag(1);
|
||||
final int tag = world.getParameters().getInt("tag", -1);
|
||||
world.getParameters().set("tag", tag + 1);
|
||||
}
|
||||
}
|
||||
return super.onSpawn(npc);
|
||||
@@ -659,7 +654,8 @@ public class HallOfErosionAttack extends AbstractNpcAI
|
||||
final L2Npc tumor = addSpawn(TUMOR_ALIVE, _deadTumor.getLocation(), _world.getInstanceId());
|
||||
_world.npcList.add(tumor);
|
||||
_deadTumor.deleteMe();
|
||||
_world.addTag(-1);
|
||||
final int tag = _world.getParameters().getInt("tag", -1);
|
||||
_world.getParameters().set("tag", tag - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -58,14 +58,8 @@ public class HallOfErosionDefence extends AbstractNpcAI
|
||||
public long startTime = 0;
|
||||
public ScheduledFuture<?> finishTask = null;
|
||||
|
||||
public synchronized void addTag(int value)
|
||||
{
|
||||
tag += value;
|
||||
}
|
||||
|
||||
public HEDWorld()
|
||||
{
|
||||
tag = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,7 +515,8 @@ public class HallOfErosionDefence extends AbstractNpcAI
|
||||
final HEDWorld world = (HEDWorld) tmpworld;
|
||||
if (npc.getId() == TUMOR_DEAD)
|
||||
{
|
||||
world.addTag(1);
|
||||
final int tag = world.getParameters().getInt("tag", -1);
|
||||
world.getParameters().set("tag", tag + 1);
|
||||
}
|
||||
}
|
||||
return super.onSpawn(npc);
|
||||
|
@@ -60,52 +60,6 @@ public class HallOfSufferingAttack extends AbstractNpcAI
|
||||
|
||||
public HSAWorld()
|
||||
{
|
||||
tag = -1;
|
||||
}
|
||||
|
||||
protected void calcRewardItemId()
|
||||
{
|
||||
final Long finishDiff = storeTime[1] - storeTime[0];
|
||||
if (finishDiff < 1260000)
|
||||
{
|
||||
tag = 13777;
|
||||
}
|
||||
else if (finishDiff < 1380000)
|
||||
{
|
||||
tag = 13778;
|
||||
}
|
||||
else if (finishDiff < 1500000)
|
||||
{
|
||||
tag = 13779;
|
||||
}
|
||||
else if (finishDiff < 1620000)
|
||||
{
|
||||
tag = 13780;
|
||||
}
|
||||
else if (finishDiff < 1740000)
|
||||
{
|
||||
tag = 13781;
|
||||
}
|
||||
else if (finishDiff < 1860000)
|
||||
{
|
||||
tag = 13782;
|
||||
}
|
||||
else if (finishDiff < 1980000)
|
||||
{
|
||||
tag = 13783;
|
||||
}
|
||||
else if (finishDiff < 2100000)
|
||||
{
|
||||
tag = 13784;
|
||||
}
|
||||
else if (finishDiff < 2220000)
|
||||
{
|
||||
tag = 13785;
|
||||
}
|
||||
else
|
||||
{
|
||||
tag = 13786;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,7 +519,49 @@ public class HallOfSufferingAttack extends AbstractNpcAI
|
||||
{
|
||||
world.incStatus();
|
||||
world.storeTime[1] = System.currentTimeMillis();
|
||||
world.calcRewardItemId();
|
||||
|
||||
final Long finishDiff = world.storeTime[1] - world.storeTime[0];
|
||||
if (finishDiff < 1260000)
|
||||
{
|
||||
world.getParameters().set("tag", 13777);
|
||||
}
|
||||
else if (finishDiff < 1380000)
|
||||
{
|
||||
world.getParameters().set("tag", 13778);
|
||||
}
|
||||
else if (finishDiff < 1500000)
|
||||
{
|
||||
world.getParameters().set("tag", 13779);
|
||||
}
|
||||
else if (finishDiff < 1620000)
|
||||
{
|
||||
world.getParameters().set("tag", 13780);
|
||||
}
|
||||
else if (finishDiff < 1740000)
|
||||
{
|
||||
world.getParameters().set("tag", 13781);
|
||||
}
|
||||
else if (finishDiff < 1860000)
|
||||
{
|
||||
world.getParameters().set("tag", 13782);
|
||||
}
|
||||
else if (finishDiff < 1980000)
|
||||
{
|
||||
world.getParameters().set("tag", 13783);
|
||||
}
|
||||
else if (finishDiff < 2100000)
|
||||
{
|
||||
world.getParameters().set("tag", 13784);
|
||||
}
|
||||
else if (finishDiff < 2220000)
|
||||
{
|
||||
world.getParameters().set("tag", 13785);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.getParameters().set("tag", 13786);
|
||||
}
|
||||
|
||||
world.klanikus = null;
|
||||
world.klodekus = null;
|
||||
cancelQuestTimers("ressurectTwin");
|
||||
|
@@ -60,52 +60,6 @@ public class HallOfSufferingDefence extends AbstractNpcAI
|
||||
|
||||
public HSDWorld()
|
||||
{
|
||||
tag = -1;
|
||||
}
|
||||
|
||||
protected void calcRewardItemId()
|
||||
{
|
||||
final Long finishDiff = storeTime[1] - storeTime[0];
|
||||
if (finishDiff < 1260000)
|
||||
{
|
||||
tag = 13777;
|
||||
}
|
||||
else if (finishDiff < 1380000)
|
||||
{
|
||||
tag = 13778;
|
||||
}
|
||||
else if (finishDiff < 1500000)
|
||||
{
|
||||
tag = 13779;
|
||||
}
|
||||
else if (finishDiff < 1620000)
|
||||
{
|
||||
tag = 13780;
|
||||
}
|
||||
else if (finishDiff < 1740000)
|
||||
{
|
||||
tag = 13781;
|
||||
}
|
||||
else if (finishDiff < 1860000)
|
||||
{
|
||||
tag = 13782;
|
||||
}
|
||||
else if (finishDiff < 1980000)
|
||||
{
|
||||
tag = 13783;
|
||||
}
|
||||
else if (finishDiff < 2100000)
|
||||
{
|
||||
tag = 13784;
|
||||
}
|
||||
else if (finishDiff < 2220000)
|
||||
{
|
||||
tag = 13785;
|
||||
}
|
||||
else
|
||||
{
|
||||
tag = 13786;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,7 +519,49 @@ public class HallOfSufferingDefence extends AbstractNpcAI
|
||||
{
|
||||
world.incStatus();
|
||||
world.storeTime[1] = System.currentTimeMillis();
|
||||
world.calcRewardItemId();
|
||||
|
||||
final Long finishDiff = world.storeTime[1] - world.storeTime[0];
|
||||
if (finishDiff < 1260000)
|
||||
{
|
||||
world.getParameters().set("tag", 13777);
|
||||
}
|
||||
else if (finishDiff < 1380000)
|
||||
{
|
||||
world.getParameters().set("tag", 13778);
|
||||
}
|
||||
else if (finishDiff < 1500000)
|
||||
{
|
||||
world.getParameters().set("tag", 13779);
|
||||
}
|
||||
else if (finishDiff < 1620000)
|
||||
{
|
||||
world.getParameters().set("tag", 13780);
|
||||
}
|
||||
else if (finishDiff < 1740000)
|
||||
{
|
||||
world.getParameters().set("tag", 13781);
|
||||
}
|
||||
else if (finishDiff < 1860000)
|
||||
{
|
||||
world.getParameters().set("tag", 13782);
|
||||
}
|
||||
else if (finishDiff < 1980000)
|
||||
{
|
||||
world.getParameters().set("tag", 13783);
|
||||
}
|
||||
else if (finishDiff < 2100000)
|
||||
{
|
||||
world.getParameters().set("tag", 13784);
|
||||
}
|
||||
else if (finishDiff < 2220000)
|
||||
{
|
||||
world.getParameters().set("tag", 13785);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.getParameters().set("tag", 13786);
|
||||
}
|
||||
|
||||
world.klanikus = null;
|
||||
world.klodekus = null;
|
||||
cancelQuestTimers("ressurectTwin");
|
||||
|
@@ -69,14 +69,8 @@ public class HeartInfinityAttack extends AbstractNpcAI
|
||||
tumorCount += value;
|
||||
}
|
||||
|
||||
public synchronized void addTag(int value)
|
||||
{
|
||||
tag += value;
|
||||
}
|
||||
|
||||
public HIAWorld()
|
||||
{
|
||||
tag = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,7 +579,8 @@ public class HeartInfinityAttack extends AbstractNpcAI
|
||||
|
||||
if (npc.getId() == DEADTUMOR)
|
||||
{
|
||||
world.addTag(1);
|
||||
final int tag = world.getParameters().getInt("tag", -1);
|
||||
world.getParameters().set("tag", tag + 1);
|
||||
}
|
||||
}
|
||||
return super.onSpawn(npc);
|
||||
@@ -661,7 +656,8 @@ public class HeartInfinityAttack extends AbstractNpcAI
|
||||
notifyTumorRevival(_world);
|
||||
_world.npcList.add(alivetumor);
|
||||
_deadTumor.deleteMe();
|
||||
_world.addTag(-1);
|
||||
final int tag = _world.getParameters().getInt("tag", -1);
|
||||
_world.getParameters().set("tag", tag - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -99,7 +99,8 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
|
||||
if ((world != null) && (world.getTemplateId() == 115))
|
||||
{
|
||||
if (world.tag == -1)
|
||||
final int tag = world.getParameters().getInt("tag", -1);
|
||||
if (tag == -1)
|
||||
{
|
||||
htmltext = "32530-11.html";
|
||||
}
|
||||
@@ -110,7 +111,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
final QuestState qs1 = member.getQuestState(getName());
|
||||
if (qs1 != null)
|
||||
{
|
||||
if (world.tag == 13777)
|
||||
if (tag == 13777)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -124,7 +125,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-00.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13778)
|
||||
else if (tag == 13778)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -138,7 +139,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-01.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13779)
|
||||
else if (tag == 13779)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -152,7 +153,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-02.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13780)
|
||||
else if (tag == 13780)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -166,7 +167,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-03.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13781)
|
||||
else if (tag == 13781)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -180,7 +181,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-04.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13782)
|
||||
else if (tag == 13782)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -194,7 +195,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-05.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13783)
|
||||
else if (tag == 13783)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -208,7 +209,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-06.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13784)
|
||||
else if (tag == 13784)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -222,7 +223,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-07.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13785)
|
||||
else if (tag == 13785)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
@@ -236,7 +237,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-08.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13786)
|
||||
else if (tag == 13786)
|
||||
{
|
||||
if (getQuestItemsCount(member, MARK) == 0)
|
||||
{
|
||||
|
@@ -108,7 +108,8 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
|
||||
if ((world != null) && (world.getTemplateId() == 116))
|
||||
{
|
||||
if (world.tag == -1)
|
||||
final int tag = world.getParameters().getInt("tag", -1);
|
||||
if (tag == -1)
|
||||
{
|
||||
htmltext = "32530-11.html";
|
||||
}
|
||||
@@ -119,7 +120,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
final QuestState qs1 = member.getQuestState(getName());
|
||||
if (qs1 != null)
|
||||
{
|
||||
if (world.tag == 13777)
|
||||
if (tag == 13777)
|
||||
{
|
||||
giveItems(member, 13777, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -129,7 +130,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-00.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13778)
|
||||
else if (tag == 13778)
|
||||
{
|
||||
giveItems(member, 13778, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -139,7 +140,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-01.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13779)
|
||||
else if (tag == 13779)
|
||||
{
|
||||
giveItems(member, 13779, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -149,7 +150,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-02.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13780)
|
||||
else if (tag == 13780)
|
||||
{
|
||||
giveItems(member, 13780, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -159,7 +160,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-03.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13781)
|
||||
else if (tag == 13781)
|
||||
{
|
||||
giveItems(member, 13781, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -169,7 +170,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-04.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13782)
|
||||
else if (tag == 13782)
|
||||
{
|
||||
giveItems(member, 13782, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -179,7 +180,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-05.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13783)
|
||||
else if (tag == 13783)
|
||||
{
|
||||
giveItems(member, 13783, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -189,7 +190,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-06.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13784)
|
||||
else if (tag == 13784)
|
||||
{
|
||||
giveItems(member, 13784, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -199,7 +200,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-07.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13785)
|
||||
else if (tag == 13785)
|
||||
{
|
||||
giveItems(member, 13785, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
@@ -209,7 +210,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
htmltext = "32530-08.html";
|
||||
finishInstance(player);
|
||||
}
|
||||
else if (world.tag == 13786)
|
||||
else if (tag == 13786)
|
||||
{
|
||||
giveItems(member, 13786, 1);
|
||||
giveItems(member, SOE, 1);
|
||||
|
@@ -23,10 +23,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.l2jmobius.gameserver.model.holders.MinionHolder;
|
||||
import com.l2jmobius.gameserver.model.holders.SkillHolder;
|
||||
import com.l2jmobius.gameserver.model.interfaces.IParserAdvUtils;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
* This class is meant to hold a set of (key,value) pairs.<br>
|
||||
@@ -187,11 +189,10 @@ public class StatsSet implements IParserAdvUtils
|
||||
}
|
||||
if (val instanceof Number)
|
||||
{
|
||||
final byte[] result =
|
||||
return new byte[]
|
||||
{
|
||||
((Number) val).byteValue()
|
||||
};
|
||||
return result;
|
||||
}
|
||||
int c = 0;
|
||||
final String[] vals = ((String) val).split(splitOn);
|
||||
@@ -319,11 +320,10 @@ public class StatsSet implements IParserAdvUtils
|
||||
}
|
||||
if (val instanceof Number)
|
||||
{
|
||||
final int[] result =
|
||||
return new int[]
|
||||
{
|
||||
((Number) val).intValue()
|
||||
};
|
||||
return result;
|
||||
}
|
||||
int c = 0;
|
||||
final String[] vals = ((String) val).split(splitOn);
|
||||
@@ -499,7 +499,11 @@ public class StatsSet implements IParserAdvUtils
|
||||
public String getString(String key, String defaultValue)
|
||||
{
|
||||
final Object val = _set.get(key);
|
||||
return val == null ? defaultValue : String.valueOf(val);
|
||||
if (val == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return String.valueOf(val);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -552,20 +556,168 @@ public class StatsSet implements IParserAdvUtils
|
||||
public final <A> A getObject(String name, Class<A> type)
|
||||
{
|
||||
final Object obj = _set.get(name);
|
||||
return (obj == null) || !type.isAssignableFrom(obj.getClass()) ? null : (A) obj;
|
||||
if ((obj == null) || !type.isAssignableFrom(obj.getClass()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (A) obj;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <A> A getObject(String name, Class<A> type, A defaultValue)
|
||||
{
|
||||
final Object obj = _set.get(name);
|
||||
if ((obj == null) || !type.isAssignableFrom(obj.getClass()))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return (A) obj;
|
||||
}
|
||||
|
||||
public SkillHolder getSkillHolder(String key)
|
||||
{
|
||||
final Object obj = _set.get(key);
|
||||
return (obj == null) || !(obj instanceof SkillHolder) ? null : (SkillHolder) obj;
|
||||
if ((obj == null) || !(obj instanceof SkillHolder))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (SkillHolder) obj;
|
||||
}
|
||||
|
||||
public Location getLocation(String key)
|
||||
{
|
||||
final Object obj = _set.get(key);
|
||||
if ((obj == null) || !(obj instanceof Location))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (Location) obj;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<MinionHolder> getMinionList(String key)
|
||||
{
|
||||
final Object obj = _set.get(key);
|
||||
return (obj == null) || !(obj instanceof List<?>) ? Collections.emptyList() : (List<MinionHolder>) obj;
|
||||
if ((obj == null) || !(obj instanceof List<?>))
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return (List<MinionHolder>) obj;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getList(String key, Class<T> clazz)
|
||||
{
|
||||
final Object obj = _set.get(key);
|
||||
if ((obj == null) || !(obj instanceof List<?>))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<Object> originalList = (List<Object>) obj;
|
||||
if (!originalList.isEmpty() && !originalList.stream().allMatch(clazz::isInstance))
|
||||
{
|
||||
if (clazz.getSuperclass() == Enum.class)
|
||||
{
|
||||
throw new IllegalAccessError("Please use getEnumList if you want to get list of Enums!");
|
||||
}
|
||||
|
||||
// Attempt to convert the list
|
||||
final List<T> convertedList = convertList(originalList, clazz);
|
||||
if (convertedList == null)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "getList(\"" + key + "\", " + clazz.getSimpleName() + ") requested with wrong generic type: " + obj.getClass().getGenericInterfaces()[0] + "!", new ClassNotFoundException());
|
||||
return null;
|
||||
}
|
||||
|
||||
// Overwrite the existing list with proper generic type
|
||||
_set.put(key, convertedList);
|
||||
return convertedList;
|
||||
}
|
||||
return (List<T>) obj;
|
||||
}
|
||||
|
||||
public <T> List<T> getList(String key, Class<T> clazz, List<T> defaultValue)
|
||||
{
|
||||
final List<T> list = getList(key, clazz);
|
||||
return list == null ? defaultValue : list;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Enum<T>> List<T> getEnumList(String key, Class<T> clazz)
|
||||
{
|
||||
final Object obj = _set.get(key);
|
||||
if ((obj == null) || !(obj instanceof List<?>))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<Object> originalList = (List<Object>) obj;
|
||||
if (!originalList.isEmpty() && (obj.getClass().getGenericInterfaces()[0] != clazz) && originalList.stream().allMatch(name -> Util.isEnum(name.toString(), clazz)))
|
||||
{
|
||||
final List<T> convertedList = originalList.stream().map(Object::toString).map(name -> Enum.valueOf(clazz, name)).map(clazz::cast).collect(Collectors.toList());
|
||||
|
||||
// Overwrite the existing list with proper generic type
|
||||
_set.put(key, convertedList);
|
||||
return convertedList;
|
||||
}
|
||||
return (List<T>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
* @param originalList
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
private <T> List<T> convertList(List<Object> originalList, Class<T> clazz)
|
||||
{
|
||||
if (clazz == Integer.class)
|
||||
{
|
||||
if (originalList.stream().map(Object::toString).allMatch(Util::isInteger))
|
||||
{
|
||||
return originalList.stream().map(Object::toString).map(Integer::valueOf).map(clazz::cast).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
else if (clazz == Float.class)
|
||||
{
|
||||
if (originalList.stream().map(Object::toString).allMatch(Util::isFloat))
|
||||
{
|
||||
return originalList.stream().map(Object::toString).map(Float::valueOf).map(clazz::cast).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
else if (clazz == Double.class)
|
||||
{
|
||||
if (originalList.stream().map(Object::toString).allMatch(Util::isDouble))
|
||||
{
|
||||
return originalList.stream().map(Object::toString).map(Double::valueOf).map(clazz::cast).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <K, V> Map<K, V> getMap(String key, Class<K> keyClass, Class<V> valueClass)
|
||||
{
|
||||
final Object obj = _set.get(key);
|
||||
if ((obj == null) || !(obj instanceof Map<?, ?>))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final Map<?, ?> originalList = (Map<?, ?>) obj;
|
||||
if (!originalList.isEmpty())
|
||||
{
|
||||
if ((!originalList.keySet().stream().allMatch(keyClass::isInstance)) || (!originalList.values().stream().allMatch(valueClass::isInstance)))
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "getMap(\"" + key + "\", " + keyClass.getSimpleName() + ", " + valueClass.getSimpleName() + ") requested with wrong generic type: " + obj.getClass().getGenericInterfaces()[0] + "!", new ClassNotFoundException());
|
||||
}
|
||||
}
|
||||
return (Map<K, V>) obj;
|
||||
}
|
||||
|
||||
public void set(String name, Object value)
|
||||
@@ -618,14 +770,19 @@ public class StatsSet implements IParserAdvUtils
|
||||
_set.put(key, value);
|
||||
}
|
||||
|
||||
public void safeSet(String key, int value, int min, int max, String reference)
|
||||
public void remove(String key)
|
||||
{
|
||||
assert ((min > max) || ((value >= min) && (value < max)));
|
||||
if ((min <= max) && ((value < min) || (value >= max)))
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "Incorrect value: " + value + "for: " + key + "Ref: " + reference);
|
||||
_set.remove(key);
|
||||
}
|
||||
|
||||
set(key, value);
|
||||
public boolean contains(String name)
|
||||
{
|
||||
return _set.containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "StatsSet{_set=" + _set + '}';
|
||||
}
|
||||
}
|
||||
|
@@ -18,9 +18,9 @@ package com.l2jmobius.gameserver.model.instancezone;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.l2jmobius.gameserver.instancemanager.InstanceManager;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
@@ -34,8 +34,7 @@ public class InstanceWorld
|
||||
private int _instanceId;
|
||||
private int _templateId = -1;
|
||||
private final List<Integer> _allowed = new CopyOnWriteArrayList<>();
|
||||
private final AtomicInteger _status = new AtomicInteger();
|
||||
public int tag = -1;
|
||||
private final StatsSet _parameters = new StatsSet();
|
||||
|
||||
public List<Integer> getAllowed()
|
||||
{
|
||||
@@ -93,24 +92,69 @@ public class InstanceWorld
|
||||
_templateId = templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set instance world parameter.
|
||||
* @param key parameter name
|
||||
* @param val parameter value
|
||||
*/
|
||||
public void setParameter(String key, Object val)
|
||||
{
|
||||
if (val == null)
|
||||
{
|
||||
_parameters.remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
_parameters.set(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance world parameters.
|
||||
* @return instance parameters
|
||||
*/
|
||||
public StatsSet getParameters()
|
||||
{
|
||||
return _parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status of instance world.
|
||||
* @return instance status, otherwise 0
|
||||
*/
|
||||
public int getStatus()
|
||||
{
|
||||
return _status.get();
|
||||
return _parameters.getInt("INSTANCE_STATUS", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if instance status is equal to {@code status}.
|
||||
* @param status number used for status comparison
|
||||
* @return {@code true} when instance status and {@code status} are equal, otherwise {@code false}
|
||||
*/
|
||||
public boolean isStatus(int status)
|
||||
{
|
||||
return _status.get() == status;
|
||||
return getStatus() == status;
|
||||
}
|
||||
|
||||
public void setStatus(int status)
|
||||
/**
|
||||
* Set status of instance world.
|
||||
* @param value new world status
|
||||
*/
|
||||
public void setStatus(int value)
|
||||
{
|
||||
_status.set(status);
|
||||
_parameters.set("INSTANCE_STATUS", value);
|
||||
}
|
||||
|
||||
public void incStatus()
|
||||
/**
|
||||
* Increment instance world status
|
||||
* @return new world status
|
||||
*/
|
||||
public int incStatus()
|
||||
{
|
||||
_status.incrementAndGet();
|
||||
final int status = getStatus() + 1;
|
||||
setStatus(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -108,6 +108,7 @@ public abstract class AbstractVariables extends StatsSet implements IRestorable,
|
||||
* Removes variable
|
||||
* @param name
|
||||
*/
|
||||
@Override
|
||||
public final void remove(String name)
|
||||
{
|
||||
_hasChanges.compareAndSet(false, true);
|
||||
|
@@ -359,6 +359,91 @@ public final class Util
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text - the text to check
|
||||
* @return {@code true} if {@code text} is integer, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isInteger(String text)
|
||||
{
|
||||
if ((text == null) || text.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
Integer.parseInt(text);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text - the text to check
|
||||
* @return {@code true} if {@code text} is float, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isFloat(String text)
|
||||
{
|
||||
if ((text == null) || text.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
Float.parseFloat(text);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text - the text to check
|
||||
* @return {@code true} if {@code text} is double, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isDouble(String text)
|
||||
{
|
||||
if ((text == null) || text.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
Double.parseDouble(text);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
* @param name - the text to check
|
||||
* @param enumType
|
||||
* @return {@code true} if {@code text} is enum, {@code false} otherwise
|
||||
*/
|
||||
public static <T extends Enum<T>> boolean isEnum(String name, Class<T> enumType)
|
||||
{
|
||||
if ((name == null) || name.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
return Enum.valueOf(enumType, name) != null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text - the text to check
|
||||
* @return {@code true} if {@code text} contains only letters and/or numbers, {@code false} otherwise
|
||||
|
Reference in New Issue
Block a user