var scriptName = "ChatBot/Soulbot";
var scriptVersion = 1.0;
var scriptAuthor = "soulplexis";

var mobs = Java.type("net.minecraft.entity.EntityCreature");
var players = Java.type("net.minecraft.entity.player.EntityPlayer");
var chatpacket = Java.type("net.minecraft.network.play.server.S02PacketChat");
var PlayerPacket = Java.type('net.minecraft.network.play.client.C03PacketPlayer');
var C00PacketKeepAlive = Java.type('net.minecraft.network.play.client.C00PacketKeepAlive');
var clientchat = Java.type("net.minecraft.network.play.client.C01PacketChatMessage");
var MathHelper = Java.type("net.minecraft.util.MathHelper");
var Potion = Java.type("net.minecraft.potion.Potion");

function randomIntFrom(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
}
var autoMessage = new autoMessage();
var autoMessageClient;

function autoMessage() {
    //textstring
    var greetings = ["hai", "I am Ming, an AI program made in Hunan", "Hello", "greetings", "こんにちは", "もしもし", "another chicken in the coop", "He has arrived", "You are late", "Stay away from me", "The new guy is here", "There you are. I've been looking for you all day", "Where have you been?", "Do you smell that..", "well well well another noob"];
    var insultresponses = ["That wasn't nice of you to say.", "No u", "You are that of an ill-tempered mouse", "You're immature", "Takes one to know one", "Right back at you", "Make better life choices", "You are useless", "Your skill level is that of a mouse", "You defy me like an ant defying a boot", "There is war in your hearts"];
    var deathresponses = ["Why'd you kill me", "You win only this time", "I will have my revenge", "It isn't nice to kill people", "You could start a war with that kind of behavior", "One more crack like that and you're out of here", "Do you even?!!", "Check does not mark the sacking of Rome", "This was not google translated", "Garage"];
    var slainresponses = ["Nice kill", "Get rekt", "Get annihilated", "	You had the temperment of a rat", "You died like your dignity", "If you are dead, you are dead now.", "Have you died?", "You haven't gotten the best of me.", "Why must the pendulum swing", "Please google the response", "Seize the means of production"];
    var permissionrespond = ["Do perform the action immediately", "Why is it necessary?", "Give me permission to do it now", "I require permission to perform the action", "You can't do that to me", "Don't tame me into this jail cell", "It took him a month to finish the meal", "You realize you're not alone as you sit in your bedroom massaging your calves after a long day of playing tug-of-war with Grandpa Joe in the hospital", "That is it, I am contacting administrators"];
    var hackingresponse = ["weee", "wow i am moving fast", "I must be going fast", "I am zooming", "i bet you can't go this fast.", "I am having fun.", "Earthquake!!!"];
    var names = ["My name is MING", "I am MING", "I'm MING", "That is for me to know only.", "I can ask you.", "I am MING and i am here to take your soul"];
    var nameagain = ["I already told you my name is MING", "I've said it already. MING", "My name.. is MING!!!", "what?! what did you say?!?!", "I am not saying it again", "It's MING", "MING!!", "you know that already"];
    var undefindd = ["I don't know what to say", "I had an error..", "I haven't been taught about that yet", "I don't know", "ask again when I get updated", "I will tell you later"];
    var godbyes = ["well goodbye", "see you later", "bye", "goodbye", "farewell", "さようなら", "再见", "bye bye", "goodbye bye", "cya", "bye honey", "another one bites the dust", "good enough"];
    var Greet = value.createBoolean("Ming", false);
    var Commands = value.createBoolean("Commands", false);
    var RobotView = value.createBoolean("ViewFix", false);
    var Failsafe = value.createBoolean("AntiSpam", false);
    var Debug = value.createBoolean("Debug", false);
    var swics = false;
    this.getName = function() {
        return "Soulplexis";
    };

    this.getDescription = function() {
        return "Automatically does things in chat.";
    };

    this.getCategory = function() {
        return "Fun";
    };
    this.onEnable = function() {
        chat.print("§csoulplexis turned on made in 2014 for vortex client TM");
        var yfixxed = false;
        var nocheat = false;
        var namesaid = false;
        var criticals = false;
        var tiss = 0;
        var soviets = 0
        var sovietanthem = false;
    }
    this.onDisable = function() {
        chat.print("§csoulplexis turned off goodbye");
    }
    this.onMotion = function() {
        if (RobotView.get()) {
            mc.thePlayer.rotationYaw = Math.round(mc.thePlayer.rotationYaw);
            mc.thePlayer.rotationPitch = Math.round(mc.thePlayer.rotationPitch);
        }
    }
    this.onUpdate = function() {
        if (sovietanthem) {
            if (soviets > 0 && soviets < 30) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.7");
            }
            if (soviets == 40) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.3");
            }
            if (soviets == 55) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.7");
            }
            if (soviets == 65) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.3");
            }
            if (soviets == 75) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.4");
            }
            if (soviets == 82) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.6");
            }
            if (soviets == 90 || soviets == 95) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.1");
            }
            if (soviets == 100) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.4");
            }
            if (soviets == 115) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.3");
            }
            if (soviets == 125) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.2");
            }
            if (soviets == 135) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.3");
            }
            if (soviets == 145) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 0.85");
            }
            if (soviets == 155) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 0.85");
            }
            if (soviets == 165 || soviets == 180) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 0.95");
            }
            if (soviets == 190) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.05");
            }
            if (soviets == 200) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.15");
            }
            if (soviets == 215) {
                mc.thePlayer.sendChatMessage("/playsound note.harp @a ~ ~ ~ 10 1.25");
            }
            soviets++;
        }
        if (Failsafe.get()) {
            if (chattimer > 0) {
                chattimer -= 1;
            }
        }
        if (yfixxed) {
            tiss++;
            if (tiss >= 2) {
                tiss = 0;
                mc.thePlayer.setPosition(mc.thePlayer.posX, mc.thePlayer.posY + 0.0000000128, mc.thePlayer.posZ);
            }
        }
        if (nocheat) {
            mc.thePlayer.sendQueue.addToSendQueue(new C00PacketKeepAlive());
            mc.thePlayer.sendQueue.addToSendQueue(new C00PacketKeepAlive());
        }
    }
    this.onAttack = function(event) {
        if (criticals) {
            var target = event.getTargetEntity();
            mc.thePlayer.onCriticalHit(target)
        }
    }
    var chattimer = 0;
    this.onPacket = function(event) {
        var packet = event.getPacket();
        if (packet instanceof clientchat) {
            if (Failsafe.get()) {
                if (chattimer != 0) {
                    event.cancelEvent();
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7Chat message deleted");
                        } else {
                            chat.print("§c[Debug] §fChat message deleted");
                        }
                    }
                } else {
                    chattimer = 20;
                }
            }
            if (Greet.get()) {
                if (packet.message == "undefined") {
                    event.cancelEvent();
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7undefined");
                        } else {
                            chat.print("§c[Debug] §fundefined");
                        }
                    }
                    mc.thePlayer.sendChatMessage(undefindd[randomIntFrom(0, (undefindd.length - 1))]);
                }
            }
            if (Commands.get()) {
                if (packet.message.contains("s!")) {
                    event.cancelEvent();
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7" + packet.message);
                        } else {
                            chat.print("§c[Debug] §f" + packet.message);
                        }
                    }
                }
                if (packet.message.contains("s!help")) {
                    chat.print("§csoulplexis command list §9prefix: s!");
                    chat.print("§ev1.2 commands that require OP are in red");
                    chat.print("help - displays command list");
                    chat.print("§4cm - instantly changes to creative");
                    chat.print("§4sm - instantly changes to survival");
                    chat.print("§4am - instantly changes to adventure mode");
                    chat.print("§4spm - instantly changes to spectator mode");
                    chat.print("§4tnt - makes everything within 10 blocks spawn tnt");
                    chat.print("§4cube - creates a 10x10x10 stone cube");
                    chat.print("§4crashnuke <pig/tnt(default)> - tries to crash (nuke or pig) the server you're on with commands (lag warning)");
                    chat.print("§4tpme - teleports every entity to you");
                    chat.print("§4pig - summons a pig ");
                    chat.print("§4thunder - plays a deep thunder noise");
                    chat.print("§4explode - fakes an explosion");
                    chat.print("§4soviet - plays the soviet anthem");
                    chat.print("c03 <true/false> - sends a C03Player packet");
                    chat.print("yfix - bypasses airwalk fly on Nocheat");
                    chat.print("nocheat - disables nocheat on localhost");
                    chat.print("criticals - enables particles");
                }
                if (packet.message.contains("s!cm")) {
                    mc.thePlayer.sendChatMessage("/gamemode creative");
                    chat.print("§ccreative mode");
                }
                if (packet.message.contains("s!sm")) {
                    mc.thePlayer.sendChatMessage("/gamemode survival");
                    chat.print("§csurvival mode");
                }
                if (packet.message.contains("s!am")) {
                    mc.thePlayer.sendChatMessage("/gamemode adventure");
                    chat.print("§cadventure time!");
                }
                if (packet.message.contains("s!spm")) {
                    mc.thePlayer.sendChatMessage("/gamemode spectator");
                    chat.print("§cspectator");
                }
                if (packet.message.contains("s!tnt")) {
                    mc.thePlayer.sendChatMessage("/execute @e[r=10] ~ ~ ~ summon PrimedTnt ~ ~ ~");
                    chat.print("§ctnt has been spawned");
                }
                if (packet.message.contains("s!cube")) {
                    mc.thePlayer.sendChatMessage("/fill ~-10 ~-1 ~-10 ~10 ~10 ~10 stone 0 outline");
                    chat.print("§ccube made");
                }
                if (packet.message.contains("s!c03")) {
                    mc.thePlayer.sendQueue.addToSendQueue(new PlayerPacket(packet.message.contains("true")));
                    chat.print("§csent packet");
                }
                if (packet.message.contains("s!yfix")) {
                    yfixxed = !yfixxed;
                    if (yfixxed) {
                        chat.print("§cyfix active");
                    } else {
                        chat.print("§cyfix inactive");
                    }
                }
                if (packet.message.contains("nocheat")) {
                    nocheat = !nocheat;
                    if (nocheat) {
                        chat.print("§cnocheat mode active");
                    } else {
                        chat.print("§cnocheat mode inactive");
                    }
                }
                if (packet.message.contains("criticals")) {
                    criticals = !criticals;
                    if (criticals) {
                        chat.print("§ccriticals active");
                    } else {
                        chat.print("§ccriticals inactive");
                    }
                }
                if (packet.message.contains("s!crashnuke")) {
                    if (packet.message.contains("pig")) {
                        mc.thePlayer.sendChatMessage("/execute @e ~ ~ ~ execute @e ~ ~ ~ summon Pig");
                        chat.print("§cserver got pigg'd");
                    } else {
                        mc.thePlayer.sendChatMessage("/execute @e ~ ~ ~ execute @e ~ ~ ~ summon PrimedTnt ~ ~ ~ {Fuse:120}");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                        chat.print("§cLEAVE THE SERVER BEFORE THE TNT EXPLODES!!!");
                    }
                    event.cancelEvent();
                }
                if (packet.message.contains("s!tp")) {
                    mc.thePlayer.sendChatMessage("/tp @e " + mc.thePlayer.getName());
                    chat.print("§cteleporting");
                }
                if (packet.message.contains("s!pig")) {
                    mc.thePlayer.sendChatMessage("/summon Pig ~1 ~ ~");
                    chat.print("§cserver got pigg'd");
                }
                if (packet.message.contains("s!thunder")) {
                    mc.thePlayer.sendChatMessage("/playsound ambient.weather.thunder @a ~ ~ ~ 10 0");
                    chat.print("§ccrack of thunder");
                }
                if (packet.message.contains("s!explode")) {
                    mc.thePlayer.sendChatMessage("/playsound random.explode @a ~ ~ ~ 10 0.75");
                    mc.thePlayer.sendChatMessage("/particle largeexplode ~ ~ ~ 2 2 2 0.1 40");
                    chat.print("§cbom");
                }
                if (packet.message.contains("s!soviet")) {
                    sovietanthem = !sovietanthem
                    soviets = 0;
                    if (sovietanthem) {
                        chat.print("§4LONG LIVE OUR SOVIET MOTHERLAND");
                    } else {
                        chat.print("§4bye bye soviets");
                    }
                }
            }
        } //ChatAI
        if (packet instanceof chatpacket) {
            var CMessage = packet.getChatComponent().getUnformattedText().toLowerCase();
            if (Greet.get()) { //greetings
                if (CMessage.contains("hi" + mc.thePlayer.getName()) || CMessage.contains(" joined the game") || CMessage.contains("welcome " + mc.thePlayer.getName())) {
                    mc.thePlayer.sendChatMessage(greetings[randomIntFrom(0, (greetings.length - 1))]);
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7" + CMessage);
                        } else {
                            chat.print("§c[Debug] §f" + CMessage);
                        }
                    }
                } // kills
                if (CMessage.contains("slain") && CMessage.contains(mc.thePlayer.getName())) {
                    if (mc.thePlayer.getHealth() == 0) { //dies
                        mc.thePlayer.sendChatMessage(deathresponses[randomIntFrom(0, (deathresponses.length - 1))]);
                        if (Debug.get()) {
                            swics = !swics
                            if (swics) {
                                chat.print("§c[Debug] §7" + CMessage);
                            } else {
                                chat.print("§c[Debug] §f" + CMessage);
                            }
                        }
                    } else { //slains
                        mc.thePlayer.sendChatMessage(slainresponses[randomIntFrom(0, (slainresponses.length - 1))]);
                        if (Debug.get()) {
                            swics = !swics
                            if (swics) {
                                chat.print("§c[Debug] §7" + CMessage);
                            } else {
                                chat.print("§c[Debug] §f" + CMessage);
                            }
                        }
                    }
                } //insult responses
                if (CMessage.contains("idiot") || CMessage.contains("retard") || CMessage.contains("degenerate") || CMessage.contains("stupid") || (CMessage.contains("l " + mc.thePlayer.getName())) || CMessage.contains("fuck") || CMessage.contains("nigger")) {
                    mc.thePlayer.sendChatMessage(insultresponses[randomIntFrom(0, (insultresponses.length - 1))]);
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7" + CMessage);
                        } else {
                            chat.print("§c[Debug] §f" + CMessage);
                        }
                    }
                } // no permission to command
                if (CMessage.contains("not have permission") || CMessage.contains("no perms") || CMessage.contains("no permission") || CMessage.contains("administrators if you believe this is in error")) {
                    mc.thePlayer.sendChatMessage(permissionrespond[randomIntFrom(0, (permissionrespond.length - 1))]);
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7" + CMessage);
                        } else {
                            chat.print("§c[Debug] §f" + CMessage);
                        }
                    }
                } //hacks
                if (CMessage.contains("hack") || CMessage.contains("hax") || CMessage.contains("cheat") && CMessage.contains(mc.thePlayer.getName())) {
                    mc.thePlayer.sendChatMessage(hackingresponse[randomIntFrom(0, (hackingresponse.length - 1))]);
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7" + CMessage);
                        } else {
                            chat.print("§c[Debug] §f" + CMessage);
                        }
                    }
                } // leaving
                if (CMessage.contains("left") || CMessage.contains("exited") || CMessage.contains("leaving")) {
                    mc.thePlayer.sendChatMessage(godbyesresponse[randomIntFrom(0, (godbyes.length - 1))]);
                    if (Debug.get()) {
                        swics = !swics
                        if (swics) {
                            chat.print("§c[Debug] §7" + CMessage);
                        } else {
                            chat.print("§c[Debug] §f" + CMessage);
                        }
                    }
                }
                // conversations
                if (((CMessage.contains("what's your name") || CMessage.contains("what is your name") || CMessage.contains("whats your name") || CMessage.contains("who are you")))) {
                    if (namesaid) {
                        mc.thePlayer.sendChatMessage(nameagain[randomIntFrom(0, (nameagain.length - 1))]);
                        if (Debug.get()) {
                            swics = !swics
                            if (swics) {
                                chat.print("§c[Debug] §7" + CMessage);
                            } else {
                                chat.print("§c[Debug] §f" + CMessage);
                            }
                        }
                    } else {
                        namesaid = true;
                        mc.thePlayer.sendChatMessage(names[randomIntFrom(0, (names.length - 1))]);
                        if (Debug.get()) {
                            swics = !swics
                            if (swics) {
                                chat.print("§c[Debug] §7" + CMessage);
                            } else {
                                chat.print("§c[Debug] §f" + CMessage);
                            }
                        }
                    }
                }
            }
        }
    }
    this.addValues = function(values) {
        values.add(Greet);
        values.add(Commands);
        values.add(Failsafe);
        values.add(RobotView);
		values.add(Debug);
    }
}

function onLoad() {};

function onEnable() {
    autoMessageClient = moduleManager.registerModule(autoMessage);
};

function onDisable() {
    moduleManager.unregisterModule(autoMessageClient);
};