From dcbfa95a9bcf369b507dd50da978e4a7cc018a23 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:03:20 +0000 Subject: [PATCH] Spawn search should consider names containing spaces. --- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminMammon.java | 41 +++++++++---- .../admincommandhandlers/AdminMammon.java | 41 +++++++++---- .../admincommandhandlers/AdminSpawn.java | 45 +++++++++++---- .../admincommandhandlers/AdminSpawn.java | 45 +++++++++++---- .../admincommandhandlers/AdminSpawn.java | 45 +++++++++++---- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- .../admincommandhandlers/AdminSpawn.java | 57 ++++++++++++------- 31 files changed, 1124 insertions(+), 575 deletions(-) diff --git a/L2J_Mobius_01.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_01.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_01.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_01.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_02.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_02.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_02.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_02.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_03.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_03.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_03.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_03.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_04.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_04.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_04.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_04.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_05.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_05.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_05.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_05.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_05.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_05.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_05.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_05.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_06.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_06.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_06.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_06.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_07.0_PreludeOfWar/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_07.0_PreludeOfWar/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_07.0_PreludeOfWar/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_07.0_PreludeOfWar/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_08.2_Homunculus/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_08.2_Homunculus/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_08.2_Homunculus/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_08.2_Homunculus/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_10.2_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_10.2_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_10.2_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_10.2_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_10.3_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_10.3_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_10.3_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_10.3_MasterClass/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java index c8b8c48243..07987d01a7 100644 --- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java +++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java @@ -17,8 +17,6 @@ package org.l2jmobius.gameserver.handler.admincommandhandlers; import java.util.Queue; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.gameserver.data.sql.NpcTable; import org.l2jmobius.gameserver.data.sql.SpawnTable; @@ -30,6 +28,7 @@ import org.l2jmobius.gameserver.model.spawn.AutoSpawnHandler; import org.l2jmobius.gameserver.model.spawn.AutoSpawnHandler.AutoSpawnInstance; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; import org.l2jmobius.gameserver.util.BuilderUtil; +import org.l2jmobius.gameserver.util.Util; /** * Admin Command Handler for Mammon NPCs @@ -152,30 +151,50 @@ public class AdminMammon implements IAdminCommandHandler { try { - // admin_list_spawns x[xxxx] x[xx] + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcTable.getInstance().getTemplateByName(params[1]).getNpcId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcTable.getInstance().getTemplateByName(searchString).getNpcId(); } + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { - activeChar.sendPacket(SystemMessage.sendString("Command format is //list_spawns [tele_index]")); + BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } + // Call the findNpcs method with the parsed NPC ID and teleport index. SpawnTable.getInstance().findNpcs(activeChar, npcId, teleportIndex); } diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java index c8b8c48243..07987d01a7 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminMammon.java @@ -17,8 +17,6 @@ package org.l2jmobius.gameserver.handler.admincommandhandlers; import java.util.Queue; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.gameserver.data.sql.NpcTable; import org.l2jmobius.gameserver.data.sql.SpawnTable; @@ -30,6 +28,7 @@ import org.l2jmobius.gameserver.model.spawn.AutoSpawnHandler; import org.l2jmobius.gameserver.model.spawn.AutoSpawnHandler.AutoSpawnInstance; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; import org.l2jmobius.gameserver.util.BuilderUtil; +import org.l2jmobius.gameserver.util.Util; /** * Admin Command Handler for Mammon NPCs @@ -152,30 +151,50 @@ public class AdminMammon implements IAdminCommandHandler { try { - // admin_list_spawns x[xxxx] x[xx] + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcTable.getInstance().getTemplateByName(params[1]).getNpcId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcTable.getInstance().getTemplateByName(searchString).getNpcId(); } + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { - activeChar.sendPacket(SystemMessage.sendString("Command format is //list_spawns [tele_index]")); + BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } + // Call the findNpcs method with the parsed NPC ID and teleport index. SpawnTable.getInstance().findNpcs(activeChar, npcId, teleportIndex); } diff --git a/L2J_Mobius_CT_0_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_CT_0_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index de2b471484..14ba0bf668 100644 --- a/L2J_Mobius_CT_0_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_CT_0_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -307,7 +305,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, !cmd.equalsIgnoreCase("admin_spawn_once")); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -315,29 +314,53 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } + + // Call the findNpcs method with the parsed NPC ID and teleport index. findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) diff --git a/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index b46fea5b77..55e142313c 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -307,7 +305,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, !cmd.equalsIgnoreCase("admin_spawn_once")); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -315,29 +314,53 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } + + // Call the findNpcs method with the parsed NPC ID and teleport index. findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index b46fea5b77..55e142313c 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -307,7 +305,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, !cmd.equalsIgnoreCase("admin_spawn_once")); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -315,29 +314,53 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } + + // Call the findNpcs method with the parsed NPC ID and teleport index. findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) diff --git a/L2J_Mobius_Classic_1.0/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_1.0/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_1.0/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_1.0/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_1.5_AgeOfSplendor/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_1.5_AgeOfSplendor/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_1.5_AgeOfSplendor/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_1.5_AgeOfSplendor/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_2.5_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_2.5_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_2.5_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_2.5_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_2.7_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_2.7_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_2.7_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_2.7_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_2.8_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_2.8_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_2.8_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_2.8_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_2.9.5_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_2.9.5_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_2.9.5_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_2.9.5_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_2.9_SecretOfEmpire/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_2.9_SecretOfEmpire/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_2.9_SecretOfEmpire/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_2.9_SecretOfEmpire/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Essence_5.2_FrostLord/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Essence_5.2_FrostLord/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Essence_5.2_FrostLord/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Essence_5.2_FrostLord/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Essence_6.2_Vanguard/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Essence_6.2_Vanguard/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Essence_6.2_Vanguard/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Essence_6.2_Vanguard/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) { diff --git a/L2J_Mobius_Essence_6.3_Crusader/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java b/L2J_Mobius_Essence_6.3_Crusader/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java index 4daf0034e0..012215d452 100644 --- a/L2J_Mobius_Essence_6.3_Crusader/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java +++ b/L2J_Mobius_Essence_6.3_Crusader/dist/game/data/scripts/handlers/admincommandhandlers/AdminSpawn.java @@ -23,8 +23,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.l2jmobius.Config; import org.l2jmobius.gameserver.data.SpawnTable; @@ -308,7 +306,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, Integer.parseInt(id), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z), h); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -334,7 +333,8 @@ public class AdminSpawn implements IAdminCommandHandler spawnMonster(activeChar, id, respawnTime, mobCount, (!cmd.equalsIgnoreCase("admin_spawn_once"))); } catch (Exception e) - { // Case of wrong or missing monster data + { + // Case of wrong or missing monster data. AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } @@ -342,37 +342,54 @@ public class AdminSpawn implements IAdminCommandHandler { int npcId = 0; int teleportIndex = -1; + try - { // admin_list_spawns x[xxxx] x[xx] + { + // Split the command into an array of words. final String[] params = command.split(" "); - final Pattern pattern = Pattern.compile("[0-9]*"); - final Matcher regexp = pattern.matcher(params[1]); - if (regexp.matches()) + final StringBuilder searchParam = new StringBuilder(); + int pos = -1; + + // Concatenate all words in the command except the first and last word. + for (String param : params) { - npcId = Integer.parseInt(params[1]); + pos++; + if ((pos > 0) && (pos < (params.length - 1))) + { + searchParam.append(param); + searchParam.append(" "); + } + } + + final String searchString = searchParam.toString().trim(); + // If the search string is a number, use it as the NPC ID. + if (Util.isDigit(searchString)) + { + npcId = Integer.parseInt(searchString); } else { - params[1] = params[1].replace('_', ' '); - npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); + // Otherwise, use it as the NPC name and look up the NPC ID. + npcId = NpcData.getInstance().getTemplateByName(searchString).getId(); } + + // If there are more than two words in the command, try to parse the last word as the teleport index. if (params.length > 2) { - teleportIndex = Integer.parseInt(params[2]); + final String lastParam = params[params.length - 1]; + if (Util.isDigit(lastParam)) + { + teleportIndex = Integer.parseInt(lastParam); + } } } catch (Exception e) { BuilderUtil.sendSysMessage(activeChar, "Command format is //list_spawns [tele_index]"); } - if (command.startsWith("admin_list_positions")) - { - findNpcs(activeChar, npcId, teleportIndex, true); - } - else - { - findNpcs(activeChar, npcId, teleportIndex, false); - } + + // Call the findNpcs method with the parsed NPC ID and teleport index. + findNpcs(activeChar, npcId, teleportIndex, command.startsWith("admin_list_positions")); } else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count")) {