Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- import java.io.*;
- import java.util.*;
- import net.minecraft.client.Minecraft;
- import org.lwjgl.input.Keyboard;
- import javax.script.*;
- public class mod_ircchat extends BaseMod {
- public static final String modbackendname="ircchat";
- public File dir;
- public File config;
- public static mod_ircchat inst;
- public GuiChatIRC gui;
- public IrcBot irc;
- public ScriptEngine engine;
- public String name;
- public int key_open = Keyboard.KEY_RETURN;
- public boolean onlySSP = false;
- public boolean closeOnEnter = false;
- public List<String> highlights = new ArrayList<String>();
- public List<String> bot_users = new ArrayList<String>();
- public String ping_sound = "random.pop";
- public float ping_volume = 1F;
- public String server = "";
- public String channel = "";
- public boolean autoconnect = false;
- public String username;
- public List<String> keys = Arrays.asList(new String[]{
- "key",
- "close_on_enter",
- "only_ssp",
- "nick",
- "highlights",
- "ping_sound",
- "ping_volume",
- "bot_users",
- "autoconnect",
- "server",
- "channel",
- "username"
- });
- public mod_ircchat() {
- try {
- inst = this;
- Minecraft mc = ModLoader.getMinecraftInstance();
- if (mc != null && mc.session != null)
- username = name = mc.session.username;
- else
- username = name = mod_ircchat.class.getName();
- dir = Minecraft.getAppDir("minecraft/mods/"+/*Settings.*/modbackendname+"/");
- config = new File(dir, "config.txt");
- loadConfig();
- saveConfig();
- if (!dir.exists())
- dir.mkdirs();
- gui = new GuiChatIRC();
- irc = new IrcBot(name, username);
- engine = new ScriptEngineManager().getEngineByName("javascript");
- if (engine != null) {
- Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
- bindings.put("game", mc);
- bindings.put("irc", irc);
- bindings.put("gui", gui);
- bindings.put("js", engine);
- bindings.put("mod", this);
- }
- if (autoconnect) {
- if (server != null && (server=server.trim()).length() !=0) {
- irc.do_connect(server);
- if (irc.isConnected()
- && channel != null
- && (channel=channel.trim()).length() != 0) {
- irc.do_join(channel);
- }
- }
- }
- } catch (Throwable e) {
- ModLoader.ThrowException("@_@", e);
- }
- }
- public Properties getCurrentProperties() {
- Properties props = new Properties();
- props.setProperty("nick", name);
- props.setProperty("ping_sound", ping_sound);
- props.setProperty("server", server);
- props.setProperty("channel", channel);
- props.setProperty("username", username);
- props.setProperty("ping_volume", String.format("%.1f", ping_volume));
- props.setProperty("only_ssp", Boolean.toString(onlySSP));
- props.setProperty("autoconnect", Boolean.toString(autoconnect));
- props.setProperty("close_on_enter", Boolean.toString(closeOnEnter));
- props.setProperty("key", Keyboard.getKeyName(key_open));
- String shl = "";
- boolean first = true;
- for (String hl: highlights) {
- if (first)
- first = false;
- else
- shl += " ";
- shl+=hl;
- }
- props.setProperty("highlights", shl);
- String susers = "";
- first = true;
- for (String user: bot_users) {
- if (first)
- first = false;
- else
- susers += " ";
- susers+=user;
- }
- props.setProperty("bot_users", susers);
- return props;
- }
- public void loadConfig(Properties props) {
- String sname = props.getProperty("nick");
- if (sname != null)
- name = sname;
- String susername = props.getProperty("username");
- if (susername != null)
- username = sname;
- String sserver = props.getProperty("server");
- if (sserver != null)
- server = sserver;
- String schannel = props.getProperty("channel");
- if (schannel != null)
- channel = schannel;
- String sping_sound = props.getProperty("ping_sound");
- if (sping_sound != null)
- ping_sound = sping_sound;
- String sonlySSP = props.getProperty("only_ssp");
- if (sonlySSP != null) {
- Boolean bonlySSP = Boolean.valueOf(sonlySSP);
- if (bonlySSP != null)
- onlySSP = bonlySSP;
- }
- String scloseOnEnter = props.getProperty("close_on_enter");
- if (scloseOnEnter != null) {
- Boolean bcloseOnEnter = Boolean.valueOf(scloseOnEnter);
- if (bcloseOnEnter != null)
- closeOnEnter = bcloseOnEnter;
- }
- String sautoconnect = props.getProperty("autoconnect");
- if (sautoconnect != null) {
- Boolean bautoconnect = Boolean.valueOf(sautoconnect);
- if (bautoconnect != null)
- autoconnect = bautoconnect;
- }
- String sping_volume = props.getProperty("ping_volume");
- if (sping_volume != null) {
- try {
- ping_volume = Float.parseFloat(sping_volume);
- } catch (NumberFormatException e) {}
- }
- String skey = props.getProperty("key");
- if (skey != null) {
- int ikey = Keyboard.getKeyIndex(skey);
- if (ikey != Keyboard.KEY_NONE)
- key_open = ikey;
- }
- String shl = props.getProperty("highlights");
- if (shl != null) {
- String[] hls = shl.split("\\s+");
- highlights = new ArrayList<String>();
- for (String hl: hls) {
- hl = hl.trim();
- if (hl.length() > 0)
- highlights.add(hl);
- }
- }
- String susers = props.getProperty("bot_users");
- if (susers != null) {
- String[] users = susers.split("\\s+");
- bot_users = new ArrayList<String>();
- for (String user: users) {
- user = user.trim();
- if (user.length() > 0)
- bot_users.add(user);
- }
- }
- }
- public void loadConfig() {
- if (!config.exists() || !config.canRead() || !config.isFile()) {
- System.out.println(mod_ircchat.class.getName()+": couldn't load config");
- }
- Properties props = new Properties();
- FileInputStream in = null;
- try {
- in = new FileInputStream(config);
- props.load(in);
- } catch (IOException e) {
- System.out.println(mod_ircchat.class.getName()+": couldn't load config");
- return;
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {}
- }
- }
- loadConfig(props);
- }
- public void saveConfig() {
- Properties props = getCurrentProperties();
- FileOutputStream out = null;
- try {
- out = new FileOutputStream(config);
- props.store(out, "---mod_ircchat---");
- } catch (IOException e) {
- System.out.println(mod_ircchat.class.getName()+": couldn't save config to "+config);
- return;
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {}
- }
- }
- }
- public void saveConfig(Properties changes) {
- loadConfig(changes);
- saveConfig();
- }
- public boolean setConfig(String key, String value) {
- if (!keys.contains(key))
- return false;
- Properties props = new Properties();
- props.setProperty(key, value);
- saveConfig(props);
- return true;
- }
- public String getConfig(String key) {
- return getCurrentProperties().getProperty(key);
- }
- public void OSDHook(Minecraft game, boolean ingui) {
- if (ingui)
- return;
- if (onlySSP && game.isMultiplayerWorld())
- return;
- if (Keyboard.isKeyDown(key_open)) {
- gui.run();
- }
- }
- public String Version() {
- return "1.2v2";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment