Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package se.proxus;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.minecraft.client.Minecraft;
- import net.minecraft.src.Packet;
- import net.minecraft.src.ScaledResolution;
- import net.minecraft.src.Session;
- import se.proxus.betterfonts.StringCache;
- import se.proxus.commands.CommandManager;
- import se.proxus.events.EventManager;
- import se.proxus.hooks.Player;
- import se.proxus.hooks.PlayerImpl;
- import se.proxus.mods.ModHandler;
- import se.proxus.tools.FileUtils;
- import se.proxus.tools.FontFactory;
- import se.proxus.tools.Location;
- public class Gallium {
- private File directory;
- private PlayerImpl player;
- private final EventManager events = new EventManager(this);
- private final ModHandler mods = new ModHandler(this);
- private final FileUtils fileUtils = new FileUtils();
- private final CommandManager commands = new CommandManager(this);
- private final FontFactory fontFactory = new FontFactory(this);
- private StringCache font;
- private StringCache fontPanel;
- private StringCache fontChat;
- /**
- * @author Oliver
- * @param type
- * Where the method gets ran from. <i>(Example; 0 (First
- * Minecraft startup.), 1 (Each time the Main menu gets
- * opened.))</i>
- */
- public void init(final int type) {
- try {
- switch (type) {
- case 0:
- getLogger().log(Level.INFO, toString() + " " + getDate());
- player = new PlayerImpl(this);
- directory = new File(getMinecraft().getMinecraftDir(),
- getName().toLowerCase());
- getDirectory().mkdirs();
- getMods().init();
- getCommands().init();
- break;
- case 1:
- if (getFont() == null) {
- setFont(new StringCache(
- getMinecraft().fontRenderer.getColorCode()));
- getFont().setDefaultFont("Lucida Console", 18, true);
- }
- if (getFontPanel() == null) {
- setFontPanel(new StringCache(
- getMinecraft().fontRenderer.getColorCode()));
- getFontPanel().setDefaultFont("Verdana", 18, true);
- }
- if (getFontChat() == null) {
- setFontChat(new StringCache(
- getMinecraft().fontRenderer.getColorCode()));
- getFontChat().setDefaultFont("Verdana Bold", 17, true);
- }
- break;
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
- /**
- * @return The clients name. <i>(Example: "Gallium")</i>
- */
- public String getName() {
- return "Gallium";
- }
- /**
- * @return The clients current version. <i>(Example: 1.53D)</i>
- */
- public double getVersion() {
- return 1.0D;
- }
- /**
- * @author Oliver
- * @return Minecrafts current version
- */
- public String getMinecraftVersion() {
- return "1.5.1";
- }
- /**
- * @return The clients Logger. <i>(Example: Logger.getLogger("Gallium"))</i>
- */
- public Logger getLogger() {
- return Logger.getLogger(toString());
- }
- /**
- * @author Oliver
- * @return Returns the clients current file. <i>(Example:
- * Client.getMinecraft().getMinecraftDir() + "/gallium/")</i>
- */
- public File getDirectory() {
- return directory;
- }
- /**
- * @return Returns the hooked player class.
- */
- public Player getPlayer() {
- return player;
- }
- /**
- * @return Returns a instance of Minecraft.java
- */
- public Minecraft getMinecraft() {
- return Minecraft.getMinecraft();
- }
- /**
- * @return Returns the clients mod handler.
- */
- public ModHandler getMods() {
- return mods;
- }
- /**
- * @author Ramisme
- * @return Returns the clients event manager.
- */
- public EventManager getEvents() {
- return events;
- }
- /**
- * @return Returns the clients file utils.
- */
- public FileUtils getFileUtils() {
- return fileUtils;
- }
- /**
- * @author Oliver
- * @return Returns the clients command manager.
- */
- public CommandManager getCommands() {
- return commands;
- }
- /**
- * @return Returns the clients font factory.
- */
- public FontFactory getFontFactory() {
- return fontFactory;
- }
- public ScaledResolution getResolution() {
- return new ScaledResolution(getMinecraft().gameSettings,
- getMinecraft().displayWidth, getMinecraft().displayHeight);
- }
- /**
- * @param packet
- * The Packet to be sent to the server.
- */
- public void sendPacket(final Packet packet) {
- getMinecraft().thePlayer.sendQueue.addToSendQueue(packet);
- }
- /**
- * A method for getting the distance between 2 locations.
- *
- * @param location1
- * Location one.
- * @param location2
- * Location two.
- * @return The distance between to locations in doubles.
- */
- public double distanceTo(final Location location1, final Location location2) {
- return location1.distanceTo(location2.getX(), location2.getY(),
- location2.getZ());
- }
- /**
- * Attempts to log you into the specified account.
- *
- * @author JordinJM
- * @param username
- * The Minecraft username/email.
- * @param password
- * The password.
- * @return If the login was successful or not.
- */
- public boolean loginToAccount(final String username, final String password) {
- try {
- URL url = new URL(
- String.format(
- "http://login.minecraft.net/?user=%s&password=%s&version=69",
- username, password));
- BufferedReader in = new BufferedReader(new InputStreamReader(url
- .openConnection().getInputStream()));
- String as[] = in.readLine().split(":");
- getMinecraft().session = new Session(as[2], as[3]);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
- /**
- * The default font for the Client. <i>(Might be used in global TTF later
- * on.)</i>
- *
- * @return The clients default font.
- */
- public StringCache getFont() {
- return font;
- }
- /**
- * Sets the clients default font.
- *
- * @param font
- * The font to be set.
- */
- public void setFont(final StringCache font) {
- this.font = font;
- }
- /**
- * The font for the 'panels' in the client.
- *
- * @return The font for the 'panels' in the client.
- */
- public StringCache getFontPanel() {
- return fontPanel;
- }
- /**
- * Sets the clients panel font.
- *
- * @param font
- * The font to be set.
- */
- public void setFontPanel(final StringCache fontPanel) {
- this.fontPanel = fontPanel;
- }
- /**
- * The font for the chat in the client.
- *
- * @return The font for the chat in the client.
- */
- public StringCache getFontChat() {
- return fontChat;
- }
- /**
- * Sets the clients chat font.
- *
- * @param font
- * The font to be set.
- */
- public void setFontChat(final StringCache fontChat) {
- this.fontChat = fontChat;
- }
- /**
- * A method for getting the computers current date, without a default
- * format.
- *
- * @param format
- * The format for the SimpleDateFormat. <i>(Example:
- * yyyy/mm/dd/hh:mm)</i>
- * @see Gallium#getDate()
- * @return Returns computers current date.
- */
- public String getDate(final String format) {
- DateFormat date = new SimpleDateFormat(format);
- Calendar calendar = Calendar.getInstance();
- return date.format(calendar.getTime());
- }
- /**
- * A method for getting the computers current date, with a default format.
- *
- * @see Gallium#getDate(String)
- * @return Returns computers current date.
- */
- public String getDate() {
- return getDate("yyyy/mm/dd/hh:mm");
- }
- @Override
- public String toString() {
- return getName() + " " + getVersion() + " (" + getMinecraftVersion()
- + ")";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement