package me.pyr0byte.vapid.modules; import java.io.File; import java.io.PrintStream; import java.util.ArrayList; import java.util.Date; import java.util.Random; import me.pyr0byte.vapid.Command; import me.pyr0byte.vapid.Vapid; import me.pyr0byte.vapid.annotations.EventHandler; import me.pyr0byte.vapid.events.ChatReceivedEvent; import me.pyr0byte.vapid.events.PlayerLogOffEvent; import me.pyr0byte.vapid.events.PlayerLogOnEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.gui.GuiPlayerInfo; import net.minecraft.client.network.NetHandlerPlayClient; public class ModuleGreet extends ModuleBase { boolean onJoin; boolean onLeave; ArrayList ignoredPlayers; String syncWith; boolean syncing; public ModuleGreet(Vapid vapid, Minecraft mc) { super(vapid, mc); this.command = new Command(this.vapid, this, this.aliases, "Greets"); this.command.registerArg("join", new Class[0], "Welcome"); this.command.registerArg("leave", new Class[0], "Good bye"); this.command.registerArg("ignore", new Class[] { String.class }, "Adds a player to the ignore list"); this.command.registerArg("unignore", new Class[] { String.class }, "Removes a player from the ignore list"); this.command.registerArg("ignored", new Class[0], "Lists ignored players"); this.command.registerArg("unignoreall", new Class[0], "Removes all ignored players"); this.ignoredPlayers = new ArrayList(); File ignored = new File("greeter_ignored.vpd"); if (ignored.exists()) { this.ignoredPlayers = this.vapid.readLines("greeter_ignored.vpd"); } this.syncWith = null; this.syncing = false; this.onJoin = true; this.onLeave = true; } String[] greetings = { "Hey", "Welcome", "Hello", "Hi", "Greetings", "Salutations", "Good to see you", "%" }; String[] goodbyes = { "Later", "So long", "See you later", "Good bye", "Bye", "Farewell" }; public void writeIgnoredPlayers() { String filename = "greeter_ignored.vpd"; File ignored = new File(filename); this.vapid.writeLines(filename, this.ignoredPlayers); } public String isPlayerOnline(String username) { for (Object o : this.mc.thePlayer.sendQueue.field_147303_b) { String s = ((GuiPlayerInfo)o).name; if (s.equalsIgnoreCase(username)) { return s; } } return null; } @EventHandler public void onChatReceived(ChatReceivedEvent e) { String player = e.getMessage().substring(0, e.getMessage().indexOf(' ') + 1); player = player.substring(1, player.length() - 2); String message = e.getMessage().substring(e.getMessage().indexOf(' ') + 1); if ((this.syncWith != null) && (this.syncWith.equalsIgnoreCase(player))) { if (message.matches(">\\s(!{3}|\\.{3})\\s.*,\\s.*(!|\\.)")) { String[] aaa = message.split(" "); String to = aaa[(aaa.length - 1)]; to = to.substring(0, to.length() - 1); boolean type = aaa[1].equals("!!!"); if (type) { greeting(to); } else { farewell(to); } } } } public String toFull(String s) { String ret = ""; char[] c = s.toCharArray(); for (char h : c) { if (h != ' ') { ret = ret + (char)((h | 0x10000) + 65248); } else { ret = ret + ' '; } } System.out.print(ret); return ret; } public void greeting(String user) { if ((!this.isEnabled) || (!this.onJoin) || (this.ignoredPlayers.contains(user.toLowerCase()))) { return; } Random rand = new Random(); int i = rand.nextInt(this.greetings.length); String period = rand.nextInt(2) > 1 ? "." : "!"; String greet = this.greetings[i]; if (greet.equals("%")) { Date d = new Date(); int t = d.getHours(); if ((t < 11) && (t > 2)) { greet = "Morning"; } else if ((t > 11) && (t < 18)) { greet = "Afternoon"; } else { greet = "Evening"; } } this.mc.thePlayer.sendChatMessage("> !!! " + greet + ", " + user + period); } public void farewell(String user) { if ((!this.isEnabled) || (!this.onLeave) || (this.ignoredPlayers.contains(user.toLowerCase()))) { return; } Random rand = new Random(); int i = rand.nextInt(this.goodbyes.length); String period = rand.nextInt(2) > 1 ? "." : "!"; this.mc.thePlayer.sendChatMessage("> ... " + this.goodbyes[i] + ", " + user + period); } @EventHandler public void onPlayerLogIn(PlayerLogOnEvent e) { greeting(e.getUsername()); } @EventHandler public void onPlayerLogOff(PlayerLogOffEvent e) { farewell(e.getUsername()); } public void processArguments(String name, String[] argv) { if (name.equals("join")) { this.onJoin = (!this.onJoin); } else if (name.equals("leave")) { this.onLeave = (!this.onLeave); } else if (name.equals("ignore")) { String player = argv[0].toLowerCase(); if (!this.ignoredPlayers.contains(player)) { this.ignoredPlayers.add(player); this.vapid.confirmMessage("Ignored " + player); writeIgnoredPlayers(); } else { this.vapid.errorMessage("As much as you hate " + argv[0] + ", you can only ignore him once"); } } else if (name.equals("unignore")) { String player = argv[0].toLowerCase(); if (this.ignoredPlayers.contains(player)) { this.ignoredPlayers.remove(player); this.vapid.confirmMessage("Unignored " + player); writeIgnoredPlayers(); } else { this.vapid.errorMessage("You never ignored " + argv[0]); } } else if (name.equals("syncing")) { this.syncing = (!this.syncing); } else if (name.equals("syncwith")) { if (isPlayerOnline(argv[0]) != null) { this.syncWith = isPlayerOnline(argv[0]); } else { this.vapid.errorMessage("That player isn't online :^("); } } else if (name.equals("ignored")) { if (this.ignoredPlayers.isEmpty()) { this.vapid.errorMessage("Nobody ignored"); return; } String ret = ""; for (String s : this.ignoredPlayers) { ret = ret + s + ", "; } ret = ret.substring(0, ret.length() - 2); this.vapid.confirmMessage(ret); } else if (name.equals("unignoreall")) { this.ignoredPlayers.clear(); writeIgnoredPlayers(); this.vapid.confirmMessage("Deleted all players from ignore list"); } } public String getMetadata() { String ret = ""; if ((this.onJoin) && (this.onLeave)) { ret = "(Join, Leave)"; } else if (this.onJoin) { ret = "(Join)"; } else if (this.onLeave) { ret = "(Leave)"; } else { ret = "(Nothing!)"; } if (this.syncing) { ret = ret + " [Synced: " + this.syncWith + "]"; } return ret; } }