aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/features/PartyUntransfer.java
blob: be4f89d91d78cd375a8cbbc68bdaa2827943cdb8 (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
package rosegoldaddons.features;

import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import rosegoldaddons.Main;

public class PartyUntransfer {
    @SubscribeEvent
    public void chat(ClientChatReceivedEvent event) {
        if (!Main.configFile.AutoUntransfer) return;
        String message = StringUtils.stripControlCodes(event.message.getUnformattedText()).toLowerCase();
        if (message.contains("the party was transferred to")) {
            String playerName = Main.mc.thePlayer.getName();
            String leader = stripRank(message.substring(message.indexOf("by")+3));
            Main.mc.thePlayer.sendChatMessage("/p transfer "+leader);
        }
        if(message.contains("has promoted")) {
            String playerName = Main.mc.thePlayer.getName();
            String leader = stripRank(message.substring(0 ,message.indexOf("has promoted")-1));
            Main.mc.thePlayer.sendChatMessage("/p transfer "+leader);
        }
    }

    private String stripRank(String name) {
        if(!name.contains("]")) {
            System.out.println("non detected");
            return name;
        }
        return name.substring(name.indexOf("]")+2);
    }
}