Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public void readData(SpoutInputStream input) throws IOException {
    String packetName = input.readString();

    boolean sandboxed = SpoutClient.isSandboxed();
    SpoutClient.enableSandbox();

    try {
      Class<? extends AddonPacket> packetClass = AddonPacket.getPacketFromId(packetName);
      Constructor<? extends AddonPacket> constructor = null;
      Constructor<? extends AddonPacket>[] constructors =
          (Constructor<? extends AddonPacket>[]) packetClass.getConstructors();
      for (Constructor<? extends AddonPacket> c : constructors) {
        if (c.getGenericParameterTypes().length == 0) {
          constructor = c;
          break;
        }
      }
      packet = constructor.newInstance();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (!sandboxed) {
      SpoutClient.disableSandbox();
    }

    int size = input.readInt();
    compressed = input.readBoolean();
    data = new byte[size];
    input.read(data);
  }
  public static Texture getTextureFromJar(String path) {
    boolean wasSandboxed = SpoutClient.isSandboxed();
    SpoutClient.disableSandbox();
    try {
      if (textures.containsKey(path)) {
        return textures.get(path);
      }

      Texture texture = null;
      // Check inside jar
      try {
        InputStream stream = Minecraft.class.getResourceAsStream(path);
        texture = TextureLoader.getTexture("PNG", stream, true, GL11.GL_NEAREST);
        stream.close();
      } catch (Exception e) {
      }
      // Check MCP/Eclipse Path
      if (texture == null) {
        texture =
            getTextureFromPath(
                FileUtil.getSpoutcraftDirectory().getAbsolutePath() + "/../.." + path);
      }

      if (texture != null) {
        textures.put(path, texture);
      }

      return texture;
    } finally {
      SpoutClient.enableSandbox(wasSandboxed);
    }
  }
  public static Texture getTextureFromPath(String path) {
    boolean wasSandboxed = SpoutClient.isSandboxed();
    SpoutClient.disableSandbox();
    try {
      if (textures.containsKey(path)) {
        return textures.get(path);
      }
      Texture texture = null;
      try {
        FileInputStream stream = new FileInputStream(path);
        if (stream.available() > 0) {
          texture = TextureLoader.getTexture("PNG", stream, true, GL11.GL_NEAREST);
        }
        stream.close();
      } catch (IOException e) {
      }

      if (texture != null) {
        textures.put(path, texture);
      }
      return texture;
    } finally {
      SpoutClient.enableSandbox(wasSandboxed);
    }
  }
 public static boolean isTextureDownloaded(String addon, String url) {
   boolean wasSandboxed = SpoutClient.isSandboxed();
   SpoutClient.disableSandbox();
   try {
     return getTextureFile(addon, url).exists();
   } finally {
     SpoutClient.enableSandbox(wasSandboxed);
   }
 }
Exemplo n.º 5
0
 public void download() {
   if (download == null && !installed) {
     downloadFail = null;
     boolean wasSandboxed = SpoutClient.isSandboxed();
     if (wasSandboxed) SpoutClient.disableSandbox();
     download = new Download(this);
     downloads.put(getId(), download);
     download.start();
     if (wasSandboxed) SpoutClient.enableSandbox();
   }
 }
Exemplo n.º 6
0
 public void save() {
   boolean wasSandboxed = SpoutClient.disableSandbox();
   Yaml yaml = new Yaml();
   HashMap<String, Object> map = new HashMap<String, Object>();
   map.put("ignore", ignorePeople);
   map.put("highlight", wordHighlight);
   try {
     yaml.dump(map, new FileWriter(getFile()));
   } catch (IOException e) {
     e.printStackTrace();
   }
   SpoutClient.enableSandbox(wasSandboxed);
 }
Exemplo n.º 7
0
 public void load() {
   boolean wasSandboxed = SpoutClient.disableSandbox();
   Yaml yaml = new Yaml();
   try {
     Object l = yaml.load(new FileReader(getFile()));
     HashMap<String, Object> map = (HashMap<String, Object>) l;
     ignorePeople = (List<String>) map.get("ignore");
     wordHighlight = (List<String>) map.get("highlight");
   } catch (FileNotFoundException e) {
     ignorePeople = new ArrayList<String>();
     wordHighlight = new ArrayList<String>();
   }
   SpoutClient.enableSandbox(wasSandboxed);
 }
Exemplo n.º 8
0
  public void run(int playerId) {
    if (packet != null) {
      SpoutInputStream stream = new SpoutInputStream(ByteBuffer.wrap(data));

      boolean sandboxed = SpoutClient.isSandboxed();
      SpoutClient.enableSandbox();
      try {
        packet.read(stream);
        packet.run();
      } catch (Exception e) {
        e.printStackTrace();
      }

      if (!sandboxed) {
        SpoutClient.disableSandbox();
      }
    }
  }
 public static Texture getTextureFromUrl(String plugin, String url, boolean download) {
   boolean wasSandboxed = SpoutClient.isSandboxed();
   SpoutClient.disableSandbox();
   try {
     File texture = getTextureFile(plugin, url);
     if (!texture.exists()) {
       return null;
     }
     try {
       return getTextureFromPath(texture.getCanonicalPath());
     } catch (IOException e) {
       e.printStackTrace();
       return null;
     }
   } finally {
     SpoutClient.enableSandbox(wasSandboxed);
   }
 }
Exemplo n.º 10
0
  public PacketAddonData(AddonPacket packet) {
    this.packet = packet;
    SpoutOutputStream stream = new SpoutOutputStream();

    boolean sandboxed = SpoutClient.isSandboxed();
    SpoutClient.enableSandbox();
    try {
      packet.write(stream);
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (!sandboxed) {
      SpoutClient.disableSandbox();
    }
    ByteBuffer buffer = stream.getRawBuffer();
    data = new byte[buffer.capacity() - buffer.remaining()];
    System.arraycopy(buffer.array(), 0, data, 0, data.length);
    needsCompression = data.length > 512;
  }
  public static String getTexturePathFromUrl(String plugin, String url) {
    if (!isTextureDownloaded(plugin, url)) {
      return null;
    }

    boolean wasSandboxed = SpoutClient.isSandboxed();
    SpoutClient.disableSandbox();
    try {
      File download = new File(FileUtil.getTempDirectory(), FileUtil.getFileName(url));
      try {
        return download.getCanonicalPath();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } finally {
      SpoutClient.enableSandbox(wasSandboxed);
    }
    return null;
  }
 public static void downloadTexture(String plugin, String url, boolean ignoreEnding) {
   boolean wasSandboxed = SpoutClient.isSandboxed();
   SpoutClient.disableSandbox();
   try {
     String fileName = FileUtil.getFileName(url);
     if (!ignoreEnding && !FileUtil.isImageFile(fileName)) {
       System.out.println("Rejecting download of invalid texture: " + fileName);
     } else if (!isTextureDownloading(url) && !isTextureDownloaded(plugin, url)) {
       File dir = FileUtil.getTempDirectory();
       if (plugin != null) {
         dir = new File(FileUtil.getCacheDirectory(), plugin);
         dir.mkdir();
       }
       Download download = new Download(fileName, dir, url, null);
       FileDownloadThread.getInstance().addToDownloadQueue(download);
     }
   } finally {
     SpoutClient.enableSandbox(wasSandboxed);
   }
 }
 public static File getTextureFile(String plugin, String url) {
   boolean wasSandboxed = SpoutClient.isSandboxed();
   SpoutClient.disableSandbox();
   try {
     String fileName = FileUtil.getFileName(url);
     File cache = cacheTextureFiles.get(plugin + File.separator + fileName);
     if (cache != null) {
       return cache;
     }
     if (plugin != null) {
       File file = FileUtil.findFile(plugin, fileName);
       if (file != null) {
         cacheTextureFiles.put(plugin + File.separator + fileName, file);
         return file;
       }
     }
     return new File(FileUtil.getTempDirectory(), fileName);
   } finally {
     SpoutClient.enableSandbox(wasSandboxed);
   }
 }
Exemplo n.º 14
0
 public void onTick() {
   tick++;
   Configuration.onTick();
   getHandle().mcProfiler.startSection("httpdownloads");
   FileDownloadThread.getInstance().onTick();
   getHandle().mcProfiler.endStartSection("packet_decompression");
   PacketDecompressionThread.onTick();
   getHandle().mcProfiler.endStartSection("widgets");
   enableSandbox();
   player.getMainScreen().onTick();
   disableSandbox();
   getHandle().mcProfiler.endStartSection("mipmapping");
   MipMapUtils.onTick();
   getHandle().mcProfiler.endStartSection("special_effects");
   if (Minecraft.theMinecraft.theWorld != null) {
     Minecraft.theMinecraft.theWorld.doColorfulStuff();
     inWorldTicks++;
   }
   getHandle().mcProfiler.endStartSection("entity_info");
   if (isSpoutEnabled()) {
     LinkedList<org.spoutcraft.api.entity.Entity> processed =
         new LinkedList<org.spoutcraft.api.entity.Entity>();
     Iterator<Entity> i = Entity.toProcess.iterator();
     while (i.hasNext()) {
       Entity next = i.next();
       if (next.spoutEntity != null) {
         processed.add(next.spoutEntity);
       }
     }
     Entity.toProcess.clear();
     if (processed.size() > 0) {
       getPacketManager().sendSpoutPacket(new PacketEntityInformation(processed));
     }
   }
   getHandle().mcProfiler.endSection();
 }