public NamedLocation create(String id, Location loc, Player player) {
   id = id.trim();
   NamedLocation warp = new NamedLocation(id, loc);
   locs.put(id.toLowerCase(), warp);
   if (player != null) {
     warp.setCreatorName(player.getName());
   } else {
     warp.setCreatorName("");
   }
   return warp;
 }
예제 #2
0
 /**
  * Packs a Pdu into the ByteBuffer.
  *
  * @throws java.nio.BufferOverflowException if buff is too small
  * @throws java.nio.ReadOnlyBufferException if buff is read only
  * @see java.nio.ByteBuffer
  * @param buff The ByteBuffer at the position to begin writing
  * @since ??
  */
 public void marshal(java.nio.ByteBuffer buff) {
   super.marshal(buff);
   orginatingEntityID.marshal(buff);
   receivingEntityID.marshal(buff);
   relationship.marshal(buff);
   partLocation.marshal(buff);
   namedLocationID.marshal(buff);
   partEntityType.marshal(buff);
 } // end of marshal method
예제 #3
0
  public int getMarshalledSize() {
    int marshalSize = 0;

    marshalSize = super.getMarshalledSize();
    marshalSize = marshalSize + orginatingEntityID.getMarshalledSize(); // orginatingEntityID
    marshalSize = marshalSize + receivingEntityID.getMarshalledSize(); // receivingEntityID
    marshalSize = marshalSize + relationship.getMarshalledSize(); // relationship
    marshalSize = marshalSize + partLocation.getMarshalledSize(); // partLocation
    marshalSize = marshalSize + namedLocationID.getMarshalledSize(); // namedLocationID
    marshalSize = marshalSize + partEntityType.getMarshalledSize(); // partEntityType

    return marshalSize;
  }
예제 #4
0
 public void marshal(DataOutputStream dos) {
   super.marshal(dos);
   try {
     orginatingEntityID.marshal(dos);
     receivingEntityID.marshal(dos);
     relationship.marshal(dos);
     partLocation.marshal(dos);
     namedLocationID.marshal(dos);
     partEntityType.marshal(dos);
   } // end try
   catch (Exception e) {
     System.out.println(e);
   }
 } // end of marshal method
  public void save() throws IOException {
    FileOutputStream output = null;

    try {
      output = new FileOutputStream(file);
      OutputStreamWriter streamWriter = new OutputStreamWriter(output, "utf-8");
      BufferedWriter writer = new BufferedWriter(streamWriter);

      CSVWriter csv = new CSVWriter(writer);

      synchronized (this) {
        for (Map.Entry<String, NamedLocation> entry : locs.entrySet()) {
          NamedLocation warp = entry.getValue();

          csv.writeNext(
              new String[] {
                warp.getName(),
                warp.getWorldName() != null
                    ? warp.getWorldName()
                    : warp.getLocation().getWorld().getName(),
                warp.getCreatorName(),
                String.valueOf(warp.getLocation().getX()),
                String.valueOf(warp.getLocation().getY()),
                String.valueOf(warp.getLocation().getZ()),
                String.valueOf(warp.getLocation().getPitch()),
                String.valueOf(warp.getLocation().getYaw()),
              });
        }
      }

      csv.flush();
      csv.close();
    } finally {
      if (output != null) {
        try {
          output.close();
        } catch (IOException e) {
        }
      }
    }
  }
예제 #6
0
  @Override
  public boolean equalsImpl(Object obj) {
    boolean ivarsEqual = true;

    if (!(obj instanceof IsPartOfPdu)) return false;

    final IsPartOfPdu rhs = (IsPartOfPdu) obj;

    if (!(orginatingEntityID.equals(rhs.orginatingEntityID))) ivarsEqual = false;
    if (!(receivingEntityID.equals(rhs.receivingEntityID))) ivarsEqual = false;
    if (!(relationship.equals(rhs.relationship))) ivarsEqual = false;
    if (!(partLocation.equals(rhs.partLocation))) ivarsEqual = false;
    if (!(namedLocationID.equals(rhs.namedLocationID))) ivarsEqual = false;
    if (!(partEntityType.equals(rhs.partEntityType))) ivarsEqual = false;

    return ivarsEqual && super.equalsImpl(rhs);
  }
 public void updateWorlds() {
   for (Iterator<Map.Entry<String, List<NamedLocation>>> i = unloadedLocs.entrySet().iterator();
       i.hasNext(); ) {
     Map.Entry<String, List<NamedLocation>> entry = i.next();
     World world = CommandBook.server().getWorld(entry.getKey());
     if (world == null) continue;
     i.remove();
     for (NamedLocation warp : entry.getValue()) {
       warp.getLocation().setWorld(world);
       locs.put(warp.getName().toLowerCase(), warp);
     }
   }
   for (Iterator<NamedLocation> i = locs.values().iterator(); i.hasNext(); ) {
     NamedLocation loc = i.next();
     if (CommandBook.server().getWorld(loc.getWorldName()) == null) {
       i.remove();
       getNestedList(unloadedLocs, loc.getWorldName()).add(loc);
     }
   }
 }
  public void load() throws IOException {
    FileInputStream input = null;
    Map<String, NamedLocation> locs = new HashMap<String, NamedLocation>();

    file.getParentFile().mkdirs();
    if (!file.exists()) {
      file.createNewFile();
    }

    try {
      input = new FileInputStream(file);
      InputStreamReader streamReader = new InputStreamReader(input, "utf-8");
      BufferedReader reader = new BufferedReader(streamReader);

      CSVReader csv = new CSVReader(reader);
      String[] line;
      while ((line = csv.readNext()) != null) {
        if (line.length < 7) {
          logger.warning("CommandBook: " + type + " data file has an invalid line with < 7 fields");
        } else {
          try {
            String name = line[0].trim().replace(" ", "");
            String worldName = line[1]; // Set to null if the world exists
            String creator = line[2];
            double x = Double.parseDouble(line[3]);
            double y = Double.parseDouble(line[4]);
            double z = Double.parseDouble(line[5]);
            float pitch = Float.parseFloat(line[6]);
            float yaw = Float.parseFloat(line[7]);

            World world = CommandBook.server().getWorld(worldName);

            if (world != null) {
              // We shouldn't have this warp
              if (castWorld != null && !castWorld.equals(world)) {
                continue;
              }
            }

            Location loc = new Location(world, x, y, z, yaw, pitch);
            NamedLocation warp = new NamedLocation(name, loc);
            warp.setWorldName(worldName);
            warp.setCreatorName(creator);
            if (world == null) {
              getNestedList(unloadedLocs, worldName).add(warp);
            } else {
              locs.put(name.toLowerCase(), warp);
            }
          } catch (NumberFormatException e) {
            logger.warning(
                "CommandBook: "
                    + type
                    + " data file has an invalid line with non-numeric numeric fields");
          }
        }
      }

      this.locs = locs;

      if (castWorld != null) {
        logger.info(
            "CommandBook: " + locs.size() + " " + type + "(s) loaded for " + castWorld.getName());
      } else {
        logger.info("CommandBook: " + locs.size() + " " + type + "(s) loaded");
      }
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (IOException e) {
        }
      }
    }
  }