summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/PosableDroneLoader.java
blob: 191ef6db83f6d6ac40c10dc677aaf50031806a6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package NET.worlds.scape;

import NET.worlds.core.Archive;
import NET.worlds.network.URL;
import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.Vector;

public class PosableDroneLoader implements Runnable {
   static final boolean debug = false;
   DroneLoader loader;
   private static boolean useCachedFiles = URL.usingCachedAvatars();
   private Vector droneList = new Vector();

   PosableDroneLoader() {
   }

   public static boolean usingCache() {
      return useCachedFiles;
   }

   public static PendingDrone makePendingDrone(PosableDrone _drone, URL _url) {
      return (PendingDrone)(useCachedFiles ? new PendingCacheDrone(_drone, _url) : new PendingDrone(_drone, _url));
   }

   public void load(PosableDrone _drone, URL _url) {
      PendingDrone pd = makePendingDrone(_drone, _url);
      this.droneList.addElement(pd);
      if (this.loader != null) {
         this.loader.wakeUp();
      }
   }

   public boolean isPending(PosableDrone _drone, URL _url) {
      Vector listCopy = (Vector)this.droneList.clone();
      Enumeration enums = listCopy.elements();

      while (enums.hasMoreElements()) {
         PendingDrone pd = (PendingDrone)enums.nextElement();
         if (pd.getUrl().toString().equals(_url.toString()) && pd.getDrone().toString().equals(_drone.toString())) {
            return true;
         }
      }

      return false;
   }

   @Override
   public void run() {
      this.loader = new DroneLoader();

      while (true) {
         this.loader.load(this.droneList);
      }
   }

   public static String getAvatarBaseName(URL pUrl) {
      String s = null;
      int dot = pUrl.getAbsolute().indexOf(46);
      if (dot != -1) {
         s = pUrl.getAbsolute().substring(7, dot);
      }

      return s;
   }

   public static boolean avatarExistsLocally(URL pUrl) throws MalformedURLException {
      if (useCachedFiles) {
         return false;
      } else if (pUrl.toString().equals(PosableShape.getDefaultURL().toString())) {
         return true;
      } else if (!pUrl.getAbsolute().substring(0, 7).equals("avatar:")) {
         throw new MalformedURLException("Not an avatar URL");
      } else {
         String s = getAvatarBaseName(pUrl);
         if (s == null) {
            throw new MalformedURLException("No file extension");
         } else {
            URL realFile = URL.make(pUrl, s + ".bod");
            return Archive.exists(realFile.unalias());
         }
      }
   }
}