How to implement queue?

Версия Minecraft
1.12.2
28
0
Good morning. I want to create a "Queue system". So I write to get some hints about it. For example, suppose that players A and B exist, if player A executes the command "/matching join", it joins a queue; if player B executes the same command, B also joins the queue. If Player A and B are in the queue, I want the server to run "/pokebattle <PlayerA> <PlayerB>".

That way, when the command is executed, change the rating_on boolean to true, make sure the player is a bronze player, and add the player to the "B MATCHING PLAYER" list. But I question because this method is a mess.

What should I do? If you have code for a system like this, please let me know.

Java:
@SubscribeEvent
    public void onLivingUpdateEvent(LivingUpdateEvent event) {
        if (event.getEntity() instanceof EntityPlayer) {
            if(CommandPokeBattle.rating_on == true) {
                try  {
                    if(bronze_player.contains(player)) {
                        B_MATCHING_PLAYER.add(player);
                        EntityPlayer player1 = B_MATCHING_PLAYER.get(1);
                        EntityPlayer player2 = B_MATCHING_PLAYER.get(2);
                        if(player1 != null && player2 != null) {
                            player.getServer().commandManager.executeCommand(player.getCommandSenderEntity(), "pokebattle " + player1.getName() + " " + player2.getName());
                            B_MATCHING_PLAYER.remove(player1);
                            B_MATCHING_PLAYER.remove(player2);
                            CommandPokeBattle.rating_on = false;
                        }
                    }
                }
            }
        }
    }
 
Решение
Such system, as you described may be implemented by follow way:
Create instance of some relevant collection(queue, list, set, I dont undestand what you need exactly), its will be "queue"

Create command handler for /matching join
When player execute this command, this player will add to the "queue"
If "queue" are contains more that two players that server will take two players, execute command pokebattle and remove this players from "queue"

Tutorial for custom command: Minecraft Modding with Forge Tutorial — Simple Command
Other example Azanor/Baubles

How to call command programmatically...
1,038
57
229
you cannot execute command on server side at player, but you can call server method.
 
7,099
324
1,510
Such system, as you described may be implemented by follow way:
Create instance of some relevant collection(queue, list, set, I dont undestand what you need exactly), its will be "queue"

Create command handler for /matching join
When player execute this command, this player will add to the "queue"
If "queue" are contains more that two players that server will take two players, execute command pokebattle and remove this players from "queue"

Tutorial for custom command: Minecraft Modding with Forge Tutorial — Simple Command
Other example Azanor/Baubles

How to call command programmatically Вызов команды
 
28
0
uch system, as you described may be implemented by follow way:
Create instance of some relevant collection(queue, list, set, I dont undestand what you need exactly), its will be "queue"

Create command handler for /matching join
When player execute this command, this player will add to the "queue"
If "queue" are contains more that two players that server will take two players, execute command pokebattle and remove this players from "queue"

Tutorial for custom command: Minecraft Modding with Forge Tutorial — Simple Command
Other example Azanor/Baubles
Java:
if(bronze_player.contains(CommandPokeBattle.Mplayer)) {
                        B_MATCHING_PLAYER.add(CommandPokeBattle.Mplayer);
                        EntityPlayer player1 = B_MATCHING_PLAYER.get(1);
                        EntityPlayer player2 = B_MATCHING_PLAYER.get(2);
                        if(player1 != null && player2 != null) {
                            CommandPokeBattle.server.commandManager.executeCommand(CommandPokeBattle.server.getServer(), "pokebattle " + player1.getName() + " " + player2.getName());
                        }
                    }
I fixed it like above code and "CommandPokeBattle.MPlayer" is a commandsender.

However, an error occurs after Player A executes the command. If Player B executes the same command immediately after that no event (log) occurs.

error..:
[18:55:56] [Server thread/WARN]: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
[18:55:56] [Server thread/WARN]:        at java.util.ArrayList.rangeCheck(Unknown Source)
[18:55:56] [Server thread/WARN]:        at java.util.ArrayList.get(Unknown Source)
[18:55:56] [Server thread/WARN]:        at kr.guebeul.pokeque.capability.score.CAPEventHandler.onLivingUpdateEvent(CAPEventHandler.java:75)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_43_CAPEventHandler_onLivingUpdateEvent_LivingUpdateEvent.invoke(.dynamic)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:187)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.common.ForgeHooks.onLivingUpdate(ForgeHooks.java:578)
[18:55:56] [Server thread/WARN]:        at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2417)
[18:55:56] [Server thread/WARN]:        at net.minecraft.entity.player.EntityPlayer.func_70071_h_(EntityPlayer.java:249)
[18:55:56] [Server thread/WARN]:        at net.minecraft.entity.player.EntityPlayerMP.func_71127_g(EntityPlayerMP.java:467)
[18:55:56] [Server thread/WARN]:        at net.minecraft.network.NetHandlerPlayServer.func_73660_a(NetHandlerPlayServer.java:246)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.func_73660_a(NetworkDispatcher.java:209)
[18:55:56] [Server thread/WARN]:        at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:235)
[18:55:56] [Server thread/WARN]:        at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:187)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:935)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:472)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:778)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:632)
[18:55:56] [Server thread/WARN]:        at java.lang.Thread.run(Unknown Source)
[18:55:56] [Server thread/WARN]: java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
[18:55:56] [Server thread/WARN]:        at java.util.ArrayList.rangeCheck(Unknown Source)
[18:55:56] [Server thread/WARN]:        at java.util.ArrayList.get(Unknown Source)
[18:55:56] [Server thread/WARN]:        at kr.guebeul.pokeque.capability.score.CAPEventHandler.onLivingUpdateEvent(CAPEventHandler.java:76)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_43_CAPEventHandler_onLivingUpdateEvent_LivingUpdateEvent.invoke(.dynamic)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:187)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.common.ForgeHooks.onLivingUpdate(ForgeHooks.java:578)
[18:55:56] [Server thread/WARN]:        at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2417)
[18:55:56] [Server thread/WARN]:        at net.minecraft.entity.player.EntityPlayer.func_70071_h_(EntityPlayer.java:249)
[18:55:56] [Server thread/WARN]:        at net.minecraft.entity.player.EntityPlayerMP.func_71127_g(EntityPlayerMP.java:467)
[18:55:56] [Server thread/WARN]:        at net.minecraft.network.NetHandlerPlayServer.func_73660_a(NetHandlerPlayServer.java:246)
[18:55:56] [Server thread/WARN]:        at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.func_73660_a(NetworkDispatcher.java:209)
[18:55:56] [Server thread/WARN]:        at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:235)
[18:55:56] [Server thread/WARN]:        at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:187)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:935)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:472)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:778)
[18:55:56] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:632)
[18:55:56] [Server thread/WARN]:        at java.lang.Thread.run(Unknown Source)
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
[18:55:56] [Server thread/INFO]: Cannot have a duplicate player in the battle.
 
28
0
Such system, as you described may be implemented by follow way:
Create instance of some relevant collection(queue, list, set, I dont undestand what you need exactly), its will be "queue"

Create command handler for /matching join
When player execute this command, this player will add to the "queue"
If "queue" are contains more that two players that server will take two players, execute command pokebattle and remove this players from "queue"

Tutorial for custom command: Minecraft Modding with Forge Tutorial — Simple Command
Other example Azanor/Baubles

How to call command programmatically Вызов команды
Java:
if(CommandPokeBattle.rating_on) {
                    if(bronze_player.contains(CommandPokeBattle.Mplayer)) {
                        B_MATCHING_PLAYER.add(CommandPokeBattle.Mplayer);
                        for(EntityPlayer player1 : B_MATCHING_PLAYER) {
                            for(EntityPlayer player2 : B_MATCHING_PLAYER) {
                                CommandPokeBattle.server.commandManager.executeCommand(CommandPokeBattle.server.getServer(), "pokebattle " + player1.getName() + " " + player2.getName());
                            }
                        }
                        CommandPokeBattle.rating_on = false;
                    }
                }
Well solved simply. Thanks for the help though! Apart from previous questions Do you know how to create a sidebar (scoreboard) and write down the contents?
 
3,005
192
592
7,099
324
1,510
Сверху