Jump to content
  • 0

a little help with ArrayList and Map


Question

Posted

hello im try to make a code but i have stuck here

first of all i have 3 npc
flag 1
flag 2
flag 3
in flag 2 i have use to spawn something guard all is works file but
am try every time to kill Flag2 to delete or kill guard if have guard alive
my problem is i have much flag and if i kill one flag the guard from all flags is delete
i need delete guard only in killed flag
here is the code

 

in flagGuard i put all name from flag npc
and after i put all spawn from FlagGuardSpawn

	public Map<String, ArrayList<L2Spawn>> _FlagGuard = new ConcurrentHashMap<>();
	public ArrayList<L2Spawn> _FlagGuardSpawn = new ArrayList<>();
	

 

and here is the delete - doDie code

is work but kill all guard from all flags

i need kill only guard from flag name
 


			for(Entry<String, ArrayList<L2Spawn>> TpGuard : FactionData.getInstance()._FlagGuard.entrySet())
			{
				if(TpGuard.getKey().equals(getName()))
				{
					for(L2Spawn g : TpGuard.getValue())
					{
						g.getNpc().doDie(null);
					}
				}
				
				System.out.println("test " + TpGuard);
			}

 

3 answers to this question

Recommended Posts

  • 0
Posted
19 hours ago, tazerman2 said:

tnx for info but can you explance me more like how can start use a map list and how can get from 20 list only one and delete him or kill guard? and if you can explance me how can put that flag with guard in a list

 

You basically ask me to describe/code you a whole system. 

 

Before you code something you need to think of a hierarchy, means how your code will look like.

Ex. each guard belong to a flag and maybe flags belong to a bases. So guards are children of flags and flags are children of bases. 

 

So we start from the top to the bottom, we move from the parents to the children.

 

Let's say we have a Flag class, we want upon spawn to spawn guards around it and upon delete or capture to delete guards. So basically this flag will own a List with the spawned guards.

 

So you create a ArrayList inside the flag that accepts guards as objects. 

Each instance has overriden methods such as onDie(), onSpawn(), deleteMe() e.t.c. 

In these events you must handle the guards.

 

Example:

 

@Override
public void onSpawn()
{
	super.onSpawn();
}

 

Here you should spawn and add to the list all your guards. 

I guess you know how to manage a spawn of an NPC.

 

After you do that you have a list full of guard objects that belong to this flag. 

Now you can manage onDie() method. Same way in there you do a for in your guard list to delete all guards, they will respawn again once the flag is spawned cause the onSpawn() will be called.

 

You should really do some tests and some practice before make such systems. 

You need learn over super and overriden methods, difference between map and a list, thread safety e.t.c. 

 

 

 

 

  • Upvote 1
  • 0
Posted (edited)

Your whole structure is wrong and this is java before VM was a thing.

 

First of all your code can be all in 1 line. You haven't understand what a MAP is and how to use it base on this code i just saw:

 

MAP.getOrDefault("key", Collections.emptyList()).forEach(s -> s.doDie(s));

 

But again this is not the best perspective.

The proper one is to bind the guards on the flag itself.

 

Either create a method on the FlagInstance.java you created such as:

 

public void addSpawn(final L2Spawn spawn)
{
   GUARD_SPAWN.computeIfAbsent("key", k -> new ArrayList<>()).add(spawn);
}

 

and on the @Override method doDie() of the FlagInstance.java simply kill and delete all guards. Then upon onSpawn() method of FlagInstance.java you can spawn again all guards.

 

In addition using a String as a key is not good nor the object itself. Instead use it's objectId and make sure to remove it upon object's delete. 

 

In addition (2). ArrayList is not thread safe since you write and delete. Use CopyOnWriteArrayList (even tho it's slow)

Edited by Kara
  • 0
Posted

tnx for info but can you explance me more like how can start use a map list and how can get from 20 list only one and delete him or kill guard? and if you can explance me how can put that flag with guard in a list

Guest
This topic is now closed to further replies.


  • Posts

    • 最优质的 Reddit 账号,专为想要影响舆论而不仅仅是阅读的人准备。 在互联网上,重要的不仅仅是观点,还有声誉。在 Reddit 上,声誉以业力值(Karma)衡量——只有少数人才能获得真正有分量的话语权。 对于企业家、营销人员、投资者和意见领袖来说,高业力账号能打开通往那些制定趋势、孕育创意、驱动数百万人的社区之门。 成为别人愿意倾听的人。推广产品、测试想法、塑造舆论——并且以强势的姿态去做。 为什么这很重要: 高业力不仅仅是你个人资料上的一个数字,它是一种能换取信任的工具。而信任是一种可以换取一切的货币。 我们的在线商店产品: 账号: Telegram、Facebook、Reddit、Twitter (X)、Instagram、YouTube、TikTok、Discord、VK、LinkedIn、GitHub、Snapchat、Gmail、电子邮箱(Outlook、Firstmail、Rambler、Onet、Gazeta、GMX、Yahoo、Proton、Web.de)、Google Voice、Google Ads 高级订阅: Telegram Premium、Twitter Premium X、YouTube Premium、Spotify Premium、Netflix Premium、Discord Nitro、ChatGPT Plus/PRO、XBOX Game Pass 附加服务: Telegram Stars、代理(IPv4、IPv6、ISP、Mobile)、VPN(Outline、WireGuard 等)、VDS/RDP 服务器 优惠码: AUGUST2025(九折优惠) 支付方式: 银行卡 · 加密货币 · 其他常用方式 购买方式: 在线商店:点击  Telegram 机器人:点击  其他服务: SMM 面板:点击 - 社交账号推广服务 使用我们的SMM面板可进行推广:Facebook、Instagram、Telegram、Spotify、Soundcloud、YouTube、Reddit、Threads、Kick、Discord、LinkedIn、Likee、VK、Twitch、Kwai、网站流量、TikTok、Trust Pilot、Apple Music、Tripadvisor、Snapchat 等等 首次试用SMM面板可获得$1奖励: 只需在我们网站提交一个主题为“Get Trial Bonus”的工单(Support) 产品列表: Reddit Karma Brute Account | 1 KARMA | 仅限 Cookies 访问(密码可能无效)| 最便宜的账号 | 起价:$1 Reddit Karma Brute Account | 20-100 发帖和评论业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS | 起价:$5 Reddit Karma Brute Account | 500-1000 发帖和评论业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS | 起价:$9 Reddit Karma Brute Account | 1000 发帖业力 + 100 评论业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS | 起价:$15 Reddit Karma Brute Account | 2000 发帖业力 + 100 评论业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS | 起价:$20 Reddit Karma Brute Account | 3000 发帖业力 + 100 评论业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS | 起价:$25 Reddit Karma Brute Account | 5000 发帖业力 + 100 评论业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS | 起价:$35 Reddit Karma Brute Account | 10000+ 业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS(包含并可用邮箱)| 起价:$45 Reddit Karma Brute Account | 20000 业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS(包含并可用邮箱)| 起价:$60 Reddit Karma Brute Account | 50000+ 业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS(包含并可用邮箱)| 起价:$90 Reddit Karma Brute Account | 100000+ 业力 | 混合 IP 注册 | 格式:USERNAME: PASSWORD:EMAIL:MAILPASS(包含并可用邮箱)| 起价:$149 忠实客户 — 额外折扣与优惠码! 九折至八折优惠或注册即送 $1 奖励 如果您想获得注册奖励 $1 或 首次购买九折至八折优惠,您可以留言: "请发给我奖励, 我的用户名是..." 您也可以在所有我们的商店首次购买时使用优惠码:"SOCNET"(85 折优惠!) 联系方式与支持: Telegram: https://t.me/socnet_support Telegram频道: https://t.me/accsforyou_shop WhatsApp: https://wa.me/79051904467  WhatsApp频道: https://whatsapp.com/channel/0029Vau0CMX002TGkD4uHa2n Discord: socnet_support  Discord服务器: https://discord.gg/y9AStFFsrh  邮箱: solomonbog@socnet.store  通过以上联系方式您还可以: — 咨询批发采购事宜 — 建立合作关系(现有合作伙伴:https://socnet.bgng.io/partners ) — 成为我们的供应商 SocNet — 数字商品与高级订阅商店 
    • we have very good discounts on clothes and adena right now!!! HURRY TO BUY
    • The Best Reddit Accounts for Those Who Want to Influence, Not Just Read. On the internet, it’s not just opinions that matter — it’s reputation. On Reddit, reputation is measured in karma — and only the select few gain access to the true weight of words. For entrepreneurs, marketers, investors, and opinion leaders — high-karma accounts open doors to communities where trends are set, ideas are formed, and millions move. Be the one they listen to. Promote products, test hypotheses, shape the narrative — and do it from a position of strength. Why it matters: High Reddit Karma is not just a number on your profile — it’s a tool that buys trust. And trust is the currency that can buy everything else. Our Online Store Selection: ➡ Accounts: Telegram, Facebook, Reddit, Twitter (X), Instagram, YouTube, TikTok, Discord, VK, LinkedIn, GitHub, Snapchat, Gmail, email services (Outlook, Firstmail, Rambler, Onet, Gazeta, GMX, Yahoo, Proton, Web.de), Google Voice, Google Ads ➡ Premium Subscriptions: Telegram Premium, Twitter Premium X, YouTube Premium, Spotify Premium, Netflix Premium, Discord Nitro, ChatGPT Plus/PRO, XBOX Game Pass ➡ Additional Services: Telegram Stars, proxies (IPv4, IPv6, ISP, Mobile), VPN (Outline, WireGuard, others), VDS/RDP servers Promo Code: AUGUST2025 (10% Discount) Payment: Bank cards · Cryptocurrency · Other popular methods How to Buy: ➡ Online Store: Click ➡ Telegram Bot: Click Other Services: ➡ SMM Panel: Click - promotion for your social media accounts. Use our SMM Panel to boost: Facebook, Instagram, Telegram, Spotify, Soundcloud, YouTube, Reddit, Threads, Kick, Discord, LinkedIn, Likee, VK, Twitch, Kwai, Website traffic, TikTok, Trust Pilot, Apple Music, Tripadvisor, Snapchat, and other digital platforms. Get $1 for your first SMM Panel trial: Just create a ticket with the subject “Get Trial Bonus” on our website (Support) Selection: ➡ Reddit Karma Brute Account | 1 KARMA | Cookies access only (password may not work) | The cheapest account | Price from: $1 ➡ Reddit Karma Brute Account | 20-100 POST AND COMMENT KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $5 ➡ Reddit Karma Brute Account | 500-1000 POST AND COMMENT KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $9 ➡ Reddit Karma Brute Account | 1000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $15 ➡ Reddit Karma Brute Account | 2000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $20 ➡ Reddit Karma Brute Account | 3000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $25 ➡ Reddit Karma Brute Account | 5000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $35 ➡ Reddit Karma Brute Account | 10000+ KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $45 ➡ Reddit Karma Brute Account | 20000 KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $60 ➡ Reddit Karma Brute Account | 50000+ KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $90 ➡ Reddit Karma Brute Account | 100000+ KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $149 Loyal customers — additional discounts and promo codes! Discount 10% - 20% or BONUS $1 for your registration If you want to receive a $1 BONUS for your registration OR a 10% - 20% discount on your first purchase, you can leave a comment: "SEND ME A BONUS, MY USERNAME IS..." You can also use the promo code for your first purchase in all our stores: "SOCNET" (15% discount!) Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp: https://wa.me/79051904467 ➡ WhatsApp Channel: https://whatsapp.com/channel/0029Vau0CMX002TGkD4uHa2n ➡ Discord: socnet_support ➡ Discord Server: https://discord.gg/y9AStFFsrh ➡ ✉ Email: solomonbog@socnet.store Through these contacts you can also: — Consult about wholesale purchases — Establish a partnership (current partners: https://socnet.bgng.io/partners ) — Become our supplier SocNet — store of digital goods and premium subscriptions
    • The Best Reddit Accounts for Those Who Want to Influence, Not Just Read. On the internet, it’s not just opinions that matter — it’s reputation. On Reddit, reputation is measured in karma — and only the select few gain access to the true weight of words. For entrepreneurs, marketers, investors, and opinion leaders — high-karma accounts open doors to communities where trends are set, ideas are formed, and millions move. Be the one they listen to. Promote products, test hypotheses, shape the narrative — and do it from a position of strength. Why it matters: High Reddit Karma is not just a number on your profile — it’s a tool that buys trust. And trust is the currency that can buy everything else. Our Online Store Selection: ➡ Accounts: Telegram, Facebook, Reddit, Twitter (X), Instagram, YouTube, TikTok, Discord, VK, LinkedIn, GitHub, Snapchat, Gmail, email services (Outlook, Firstmail, Rambler, Onet, Gazeta, GMX, Yahoo, Proton, Web.de), Google Voice, Google Ads ➡ Premium Subscriptions: Telegram Premium, Twitter Premium X, YouTube Premium, Spotify Premium, Netflix Premium, Discord Nitro, ChatGPT Plus/PRO, XBOX Game Pass ➡ Additional Services: Telegram Stars, proxies (IPv4, IPv6, ISP, Mobile), VPN (Outline, WireGuard, others), VDS/RDP servers Promo Code: AUGUST2025 (10% Discount) Payment: Bank cards · Cryptocurrency · Other popular methods How to Buy: ➡ Online Store: Click ➡ Telegram Bot: Click Other Services: ➡ SMM Panel: Click - promotion for your social media accounts. Use our SMM Panel to boost: Facebook, Instagram, Telegram, Spotify, Soundcloud, YouTube, Reddit, Threads, Kick, Discord, LinkedIn, Likee, VK, Twitch, Kwai, Website traffic, TikTok, Trust Pilot, Apple Music, Tripadvisor, Snapchat, and other digital platforms. Get $1 for your first SMM Panel trial: Just create a ticket with the subject “Get Trial Bonus” on our website (Support) Selection: ➡ Reddit Karma Brute Account | 1 KARMA | Cookies access only (password may not work) | The cheapest account | Price from: $1 ➡ Reddit Karma Brute Account | 20-100 POST AND COMMENT KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $5 ➡ Reddit Karma Brute Account | 500-1000 POST AND COMMENT KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $9 ➡ Reddit Karma Brute Account | 1000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $15 ➡ Reddit Karma Brute Account | 2000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $20 ➡ Reddit Karma Brute Account | 3000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $25 ➡ Reddit Karma Brute Account | 5000 Post Karma and 100 Comment Karma | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS | Price from: $35 ➡ Reddit Karma Brute Account | 10000+ KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $45 ➡ Reddit Karma Brute Account | 20000 KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $60 ➡ Reddit Karma Brute Account | 50000+ KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $90 ➡ Reddit Karma Brute Account | 100000+ KARMA | MIX IP Registered | FORMAT: USERNAME:PASSWORD:EMAIL:MAILPASS (email included and working) | Price from: $149 Loyal customers — additional discounts and promo codes! Discount 10% - 20% or BONUS $1 for your registration If you want to receive a $1 BONUS for your registration OR a 10% - 20% discount on your first purchase, you can leave a comment: "SEND ME A BONUS, MY USERNAME IS..." You can also use the promo code for your first purchase in all our stores: "SOCNET" (15% discount!) Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp: https://wa.me/79051904467 ➡ WhatsApp Channel: https://whatsapp.com/channel/0029Vau0CMX002TGkD4uHa2n ➡ Discord: socnet_support ➡ Discord Server: https://discord.gg/y9AStFFsrh ➡ ✉ Email: solomonbog@socnet.store Through these contacts you can also: — Consult about wholesale purchases — Establish a partnership (current partners: https://socnet.bgng.io/partners ) — Become our supplier SocNet — store of digital goods and premium subscriptions
    • https://forum.smart-guard.eu/login/ maybe try here idk
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock