aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/commands/SetPartyCommand.java
blob: 40551d3c13c9196d0133f56fc7452e94ee566f6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package me.Danker.commands;

import me.Danker.DankersSkyblockMod;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;

import java.util.Arrays;

public class SetPartyCommand extends CommandBase implements ICommand {

    public static boolean set = false;
    public static int delimiter = 0;
    public static boolean gettingParty;
    public static String partyResponse = "";

    @Override
    public String getCommandName() { return "setparty"; }
    public static String getName() { return "setparty"; }

    @Override
    public String getCommandUsage(ICommandSender sender) { return "/" + getCommandName() + " <Party members>"; }
    public static String getUsage(){ return "/" + getName() + " <Party members>"; }

    @Override
    public int getRequiredPermissionLevel() { return 0; }

    @Override
    public void processCommand(ICommandSender sender, String[] args) throws CommandException {
        final EntityPlayer player = (EntityPlayer) sender;

        if(args.length == 0) {
            player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "Usage: " + getCommandUsage(sender)));
            return;
        }

        RepartyCommand.players = args;

        String members = String.join("\n" + EnumChatFormatting.GOLD,RepartyCommand.players);
        player.addChatMessage(new ChatComponentText(DankersSkyblockMod.DELIMITER_COLOUR + "" + EnumChatFormatting.BOLD + "-------------------\n" +
                EnumChatFormatting.GOLD + members + "\n" +
                DankersSkyblockMod.DELIMITER_COLOUR + "" + EnumChatFormatting.BOLD + "-------------------"));

        set = true;
    }

    public static void getParty() {
        gettingParty = true;
        partyResponse = "";
        Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl");
        (new Thread(() ->{
            try{
                Thread.sleep(500);
                RepartyCommand.players = Arrays.stream(partyResponse.split(" ")).filter(e -> !e.contains("[") && !e.contains("●")).toArray(String[]::new);
                set = true;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        })).start();
    }
}