Swapped from list to set to prevent duplicates

Use a set instead, clone instead of adding directly to the list.
This commit is contained in:
James McDowell
2021-05-20 19:16:22 +10:00
parent 0345ce844e
commit 9128329d37
3 changed files with 6 additions and 4 deletions

View File

@@ -307,6 +307,6 @@ public class ServerConfig {
//Event End Timestamp //Event End Timestamp
public long EVENT_END_TIMESTAMP; public long EVENT_END_TIMESTAMP;
//Custom NPC overrides. NPC ID to Name pair. //Custom NPC overrides. List of NPC IDs.
public List<Integer> NPCS_SCRIPTABLE = new ArrayList<>(); public List<Integer> NPCS_SCRIPTABLE = new ArrayList<>();
} }

View File

@@ -408,14 +408,16 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
} }
if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) { if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) {
List<Integer> npcsIds = YamlConfig.config.server.NPCS_SCRIPTABLE;
// Create a set to remove duplicate entries if they exist.
Set<Integer> npcsIds = new HashSet<>(YamlConfig.config.server.NPCS_SCRIPTABLE);
// Any npc be specified as the rebirth npc. Allow the npc to use custom scripts explicitly. // Any npc be specified as the rebirth npc. Allow the npc to use custom scripts explicitly.
if (YamlConfig.config.server.USE_REBIRTH_SYSTEM) { if (YamlConfig.config.server.USE_REBIRTH_SYSTEM) {
npcsIds.add(YamlConfig.config.server.REBIRTH_NPC_ID); npcsIds.add(YamlConfig.config.server.REBIRTH_NPC_ID);
} }
c.announce(MaplePacketCreator.setNPCScriptable(YamlConfig.config.server.NPCS_SCRIPTABLE)); c.announce(MaplePacketCreator.setNPCScriptable(npcsIds));
} }
if(newcomer) player.setLoginTime(System.currentTimeMillis()); if(newcomer) player.setLoginTime(System.currentTimeMillis());

View File

@@ -8326,7 +8326,7 @@ public class MaplePacketCreator {
* @param scriptableNpcIds Ids of npcs to enable scripts for. * @param scriptableNpcIds Ids of npcs to enable scripts for.
* @return a packet which makes the npc's provided scriptable. * @return a packet which makes the npc's provided scriptable.
*/ */
public static byte[] setNPCScriptable(List<Integer> scriptableNpcIds) { // thanks to GabrielSin public static byte[] setNPCScriptable(Set<Integer> scriptableNpcIds) { // thanks to GabrielSin
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue()); mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue());
mplew.write(scriptableNpcIds.size()); mplew.write(scriptableNpcIds.size());