Addition of generic getRandomEntry method.
This commit is contained in:
@@ -51,7 +51,7 @@ public class Toma extends AbstractNpcAI
|
||||
{
|
||||
if (event.equals("RESPAWN_TOMA"))
|
||||
{
|
||||
addSpawn(TOMA, LOCATIONS[getRandom(LOCATIONS.length)], false, TELEPORT_DELAY);
|
||||
addSpawn(TOMA, getRandomEntry(LOCATIONS), false, TELEPORT_DELAY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ public class TimakOrcTroopLeader extends AbstractNpcAI
|
||||
{
|
||||
addMinion((MonsterInstance) npc, is.getId());
|
||||
}
|
||||
npc.broadcastSay(ChatType.NPC_GENERAL, ON_ATTACK_MSG[getRandom(ON_ATTACK_MSG.length)]);
|
||||
npc.broadcastSay(ChatType.NPC_GENERAL, getRandomEntry(ON_ATTACK_MSG));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ public class FactionSystem extends AbstractNpcAI
|
||||
{
|
||||
if (npc != null)
|
||||
{
|
||||
npc.broadcastSay(ChatType.NPC_GENERAL, TEXTS[getRandom(TEXTS.length)], 1500);
|
||||
npc.broadcastSay(ChatType.NPC_GENERAL, getRandomEntry(TEXTS), 1500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -95,8 +95,7 @@ public class Elpies extends Event
|
||||
|
||||
EVENT_ACTIVE = true;
|
||||
|
||||
final EventLocation[] locations = EventLocation.values();
|
||||
final EventLocation randomLoc = locations[getRandom(locations.length)];
|
||||
final EventLocation randomLoc = getRandomEntry(EventLocation.values());
|
||||
|
||||
CURRENT_ELPY_COUNT = 0;
|
||||
final long despawnDelay = EVENT_DURATION_MINUTES * 60000;
|
||||
|
@@ -3005,22 +3005,43 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
|
||||
|
||||
/**
|
||||
* Get a random entry.<br>
|
||||
* @param entry array with values.
|
||||
* @return random one value from array entry.
|
||||
* @param <T>
|
||||
* @param array of values.
|
||||
* @return one value from array.
|
||||
*/
|
||||
public static String getRandomEntry(String... entry)
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getRandomEntry(T... array)
|
||||
{
|
||||
return entry[getRandom(entry.length)];
|
||||
if (array.length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return array[getRandom(array.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random entry.<br>
|
||||
* @param entry array with values.
|
||||
* @return random one value from array entry.
|
||||
* @param <T>
|
||||
* @param list of values.
|
||||
* @return one value from list.
|
||||
*/
|
||||
public static int getRandomEntry(int... entry)
|
||||
public static <T> T getRandomEntry(List<T> list)
|
||||
{
|
||||
return entry[getRandom(entry.length)];
|
||||
if (list.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list.get(getRandom(list.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random entry.<br>
|
||||
* @param array of Integers.
|
||||
* @return one Integer from array.
|
||||
*/
|
||||
public static int getRandomEntry(int... array)
|
||||
{
|
||||
return array[getRandom(array.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user