Package com.kellerkindt.scs.internals

Examples of com.kellerkindt.scs.internals.Storage


    try {
      int   ver   = Integer.parseInt(version);
      UUID  id    = ver >= 6 ? UUID.fromString(uuid) : UUID.randomUUID();
     
      // Add the storage
      Storage  storage  = new Storage(Integer.parseInt(version), id);
     
      // set for storage
      this.currentIsNoStorage--;
     
      // set storage
View Full Code Here


      HashMap<String, String>  atts  = this.elementAttributes.get(elementAttributes.size()-1);
      String          content  = this.elementContents  .get(elementContents.size()-1).toString();
     
      String          name  = localName;
      String          type  = atts.get(elementAttrType);
      Storage          storage  = elementStorages.get(elementStorages.size()-1);

     
      // remove last ones - because it ends here - has to be BEFORE the if!!!
      this.elementAttributes  .remove(elementAttributes  .size()-1);
      this.elementContents  .remove(elementContents     .size()-1);
     
     
      // check for missing attributes
      if (atts == null || content == null || content.length() == 0 || name == null | type == null ||  storage == null)
        return;
     
      // has to be AFTER the if !!!!
      this.currentIsNoStorage--;
     
     
      // Storage
      if (elementAttrTypeStorage.equalsIgnoreCase(type) || type == null) {
       
        if (elementStorages.size() > 1// > 1 because of the main storage...
          elementStorages.remove(storage)// remove the last storage
      }
     
      // entry
      else if (elementAttrTypeEntry.equals(type)) {
        @SuppressWarnings("unchecked")
        List<Object> list = (List<Object>)elementLists.get(currentIsNoStorage);
       
        if (list == null) {
          list = new ArrayList<Object>();
          elementLists.put(currentIsNoStorage, list);
        }
       
        if (elementAttrTypeString.equalsIgnoreCase(name)) {
          list.add(content);
         
        } else if (elementAttrTypeDouble.equalsIgnoreCase(name)) {
          list.add(Double.parseDouble(content));
         
        } else if (elementAttrTypeInteger.equalsIgnoreCase(name)) {
          list.add(Integer.parseInt(content));
         
        } else if (elementAttrTypeBoolean.equalsIgnoreCase(name)) {
          list.add(Boolean.parseBoolean(content));
        }
      }
     
      // String
      else if (elementAttrTypeString.equalsIgnoreCase(type))
        storage.setString(name, content);
     
      // Double
      else if (elementAttrTypeDouble.equalsIgnoreCase(type))
        storage.setDouble(name, Double.parseDouble(content));
     
      // Integer
      else if (elementAttrTypeInteger.equalsIgnoreCase(type))
        storage.setInteger(name, Integer.parseInt(content));
     
      // Boolean
      else if (elementAttrTypeBoolean.equalsIgnoreCase(type))
        storage.setBoolean(name, Boolean.parseBoolean(content));
     
     
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

   * @throws SAXException
   * @throws IOException
   * @throws ParserConfigurationException
   */
  private Storage loadXMLStorageFromFile (File file) throws SAXException, IOException, ParserConfigurationException {
    Storage  storage  = parser.loadStorage(file);
   
    if (storage != null) {
     
      /*
       * Since version 6, a UUID is used
       * instead of a sha1 key, so delete
       * the old file
       * --> REWRITE NOW
       */
      if (storage.getVersion() <= 5) {
        try {
          saveStorageToXMLFile(file, storage);
        } catch (Exception e) {
          scs.log(Level.SEVERE, "Couldn't save new storage, trying again later", false);
        }
      }
     
      // only raw loading
//      storage = update(storage, storage.getVersion(), Properties.storageVersion);
     
      // reset, will be added to the list if an update was done
      storage.resetHasChanged();
    }
   
    return storage;
  }
View Full Code Here

    List<Shop>  shops  = new ArrayList<Shop>();
   
    for (File file : dataDir.listFiles()) {
      try {
       
        Storage storage = loadXMLStorageFromFile(file);
        shops.add(ShopImporter.loadShop(storage, new WorldProvider() {
         
          @Override
          public World getWorld(String name) {
            return scs.getServer().getWorld(name);
View Full Code Here

      // get the string with the information
      String    sItemStackName  = storage.getString  (args[0]);
      String    sMaterial    = storage.getString  (args[2]);
      String    sEnchantments  = storage.getString  (args[3]);
      String    sNBTItemStack  = storage.getString  (args[4]);
      Storage    storNBT      = storage.getStorage(args[5]);
     
      // the version where the information is in the ItemStackName?
      if (sItemStackName != null) {
        String    splitted[]    = sItemStackName.split(splitItemParams);
        int      id        = Integer.parseInt(splitted[0]);
       
        // has durability?
        if (splitted.length > 1) {
          itemStack =  new ItemStack(id, Properties.DEFAULT_STACK_AMOUNT, Short.parseShort(splitted[1]));
        } else {
          itemStack = new ItemStack(id, Properties.DEFAULT_STACK_AMOUNT);
        }
       
       
      // the version when the information was in the Material?
      } else if (sMaterial != null) {
        String    splitted[]    = sMaterial.split(splitItemParams);
        Material  material    = Material.getMaterial(splitted[0].toUpperCase());
       
        // has durability?
        if (splitted.length > 1) {
          itemStack = new ItemStack(material, Properties.DEFAULT_STACK_AMOUNT, Short.parseShort(splitted[1]));
        } else {
          itemStack = new ItemStack(material, Properties.DEFAULT_STACK_AMOUNT);
        }
      }
       
      // couldn't load the ItemStack?
      if (itemStack == null) {
        throw new NullPointerException("ItemStack is null");
      }
     
     
      // any additional information in the NBT String?
      if (sNBTItemStack != null) {
        byte[]          bytes  = new HexBinaryAdapter().unmarshal(sNBTItemStack);
        ByteArrayInputStream  bais  = new ByteArrayInputStream(bytes);
        DataInputStream      dis    = new DataInputStream(bais);
       
        // MC 1.4.6
        if (version.contains("1.4.6")) {
          net.minecraft.server.v1_4_R1.NBTBase    tag    = net.minecraft.server.v1_4_R1.NBTBase.b(dis);
          net.minecraft.server.v1_4_R1.ItemStack  stack  = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asNMSCopy(itemStack);
         
          stack.setTag((net.minecraft.server.v1_4_R1.NBTTagCompound)tag);
         
          itemStack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asBukkitCopy(stack);
          ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from DIS - MC 1.4.6");
         
        // MC 1.4.5
        } else if (version.contains("1.4.5")) {
          net.minecraft.server.v1_4_5.NBTBase    tag    = net.minecraft.server.v1_4_5.NBTBase.b(dis);
          net.minecraft.server.v1_4_5.ItemStack  stack  = org.bukkit.craftbukkit.v1_4_5.inventory.CraftItemStack.asNMSCopy(itemStack);
         
          stack.setTag((net.minecraft.server.v1_4_5.NBTTagCompound)tag);
         
          itemStack = org.bukkit.craftbukkit.v1_4_5.inventory.CraftItemStack.asBukkitCopy(stack);
          ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from DIS - MC 1.4.5");
         
        }
      }
     
     
      // any additional information in the NBTStorage?
      if (storNBT != null) {
        // MC 1.4.5
        if (version.contains("1.4.5")) {
          net.minecraft.server.v1_4_R1.ItemStack  stack  = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asNMSCopy(itemStack);
         
          stack.setTag(new com.kellerkindt.scs.internals.NBTStorage(storNBT).getNBTTagCompound());
         
          itemStack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asBukkitCopy(stack);
          ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from NBTStorage - MC 1.4.5");
       
        // MC 1.4.6
        } else if (version.contains("1.4.6")) {
         

          String tagStringAuthor    = "author";
          String tagStringTitle    = "title";
          String tagStringPages    = "pages";
          String tagStringPagePref  = "page-";
         
          String tagIntegerPagesSize   = "pages";
         
         
          String   author  = storNBT.getString  (tagStringAuthor);
          String   title  = storNBT.getString  (tagStringTitle);
          Integer pSize  = storNBT.getInteger(tagIntegerPagesSize);
         
          net.minecraft.server.v1_4_R1.NBTTagCompound compound  = new net.minecraft.server.v1_4_R1.NBTTagCompound();
         
          if (pSize != null) {
            net.minecraft.server.v1_4_R1.NBTTagList  list  = new net.minecraft.server.v1_4_R1.NBTTagList();
            for (int i = 0; i < pSize; i++) {
              String       page  = storNBT.getString(tagStringPagePref+i);
             
              if (page != null) {
                net.minecraft.server.v1_4_R1.NBTTagString tag  = new net.minecraft.server.v1_4_R1.NBTTagString(page);
                tag.data      = page;
                list.add(tag);
              }
            }
           
            compound.set(tagStringPages, list);
          }
         
          if (title != null)
            compound.setString(tagStringTitle, title);
         
          if (author != null)
            compound.setString(tagStringAuthor, author);
         
         
          net.minecraft.server.v1_4_R1.ItemStack  stack  = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asNMSCopy(itemStack);
         
          stack.setTag(compound);
         
          itemStack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asBukkitCopy(stack);
          ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from NBTStorage - MC 1.4.6");
         
         
        }
      }
     
      // enchantments available?
      Map<Enchantment, Integer> enchantments = null;
     
      if (sEnchantments != null) {
        enchantments = new HashMap<Enchantment, Integer>();
       
        String ench[]    = sEnchantments.split(",");
        for (String string : ench) {
          Enchantment  enchantment  = Utilities.getEnchantmentFromString    (string);
          int      level    = Utilities.getEnchantmentLevelFromString  (string);
         
          if (enchantment != null) {
            enchantments.put(enchantment, level);
          }

        }
      }
     
      // add the enchantments if there are set some
      if (enchantments != null) {
        for (Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
         
          if (Properties.allowUnsafeEnchantments) {
            itemStack.addUnsafeEnchantment(entry.getKey(), entry.getValue());
          } else {
            itemStack.addEnchantment(entry.getKey(), entry.getValue());
          }
        }
      }
    }
   
   
    // storage version 4
    else if (interpretationVersion == 4) {
      // load binary array
      String   hexString  = storage.getString(args[0]);
      byte[]  array    = new HexBinaryAdapter().unmarshal(hexString);
     
      // init streams
      ByteArrayInputStream  bais  = new ByteArrayInputStream(array);
      ObjectInputStream    ois    = new ObjectInputStream(bais);
     
      // get the map and the ItemStack
      @SuppressWarnings("unchecked")
      HashMap<String, Object>  map    = (HashMap<String, Object>)ois.readObject();
      itemStack            = ItemStack.deserialize(map);
     
     
    }
   
    // storage version 5
    else if (interpretationVersion == 5) {
     
      // load it from the hex String
      itemStack = Utilities.toItemStack(storage.getString(args[0]), Properties.DEFAULT_STACK_AMOUNT);
     
      Validate.notNull(itemStack);
     
      if (storage.getStorage(args[1]) != null) {
        itemStack.setItemMeta( Utilities.toItemMeta(storage.getString(args[1])) );
      }
    }
   
    // storage version 6
    else if (interpretationVersion >= 6) {
     
      Storage itemStorage = storage.getStorage(args[6]);
     
      if (itemStorage != null) {
        itemStack = new ItemStorage(itemStorage).getItemStack();
       
        Validate.notNull(itemStack);
View Full Code Here

      }
       
     
      // load storages
      for (UUID uuid : uuids.keySet()) {
        Storage  storage  = loadStorage(uuid, uuids.get(uuid));
       
        if (storage != null) {
          storage = update(storage, storage.getVersion(), Properties.storageVersion);
          addRaw(storage);
        } else {
          changed.add(uuid)// so its deleted the next time
        }
      }
View Full Code Here

      PreparedStatement   statement  = connection.prepareStatement(getPreparedQuery(SQL_SELECT_STORAGES_WHERE, SQL_COLUMN_USID));
                statement.setString(1, uuid.toString());
     
      ResultSet        result      = statement.executeQuery();
      HashMap<String, String>  storages    = new HashMap<String, String>()// variable name, id:version
      Storage          storage      = new Storage(version, uuid);
     
      while (result.next()) {
       
        String  type  = result.getString(SQL_COLUMN_TYPE);
        String  name  = result.getString(SQL_COLUMN_NAME);
        String  value  = result.getString(SQL_COLUMN_VALUE);
       
        if (TYPE_STRING.equalsIgnoreCase(type)) {
//          if (value != null && !value.equals("\0x00"))
//            storage.setString(name, value.replaceAll("\0x0|\000|\0x3|\003|0x8|\008", " "));
          storage.setString(name, value);
        }
       
        else if (TYPE_DOUBLE.equalsIgnoreCase(type))
          storage.setDouble(name, Double.parseDouble(value));
       
        else if (TYPE_INTEGER.equalsIgnoreCase(type))
          storage.setInteger(name, Integer.parseInt(value));
       
        else if (TYPE_BOOLEAN.equalsIgnoreCase(type))
          storage.setBoolean(name, Boolean.parseBoolean(value));
       
        else if (TYPE_STORAGE.equalsIgnoreCase(type))
          storages.put(name, value);
       
      }
     
      for (String name : storages.keySet()) {
        String  s  = storages.get(name);
        String   id  =           s.split(SPLIT_STORAGE_VERSION_BY)[0];
        int    ver  = Integer.parseInts.split(SPLIT_STORAGE_VERSION_BY)[1] );
        UUID  uu  = null;
       
        /*
         * Since version 6 the sha1 key
         * is replaced by a UUID
         */
        if (ver >= 6) {
          uu = UUID.fromString(id);
         
        } else {
          uu = UUID.randomUUID();
        }
       
        storage.setStorage(name, loadStorage(uu, ver));
      }
     
      storage.resetHasChanged();
      return storage;
     
    } catch (Exception e) {
      scs.log(Level.WARNING, "Couldn't load storage with usid="+uuid, false);
      e.printStackTrace();
View Full Code Here

      statement.execute();
    }
   
    // save storage-ids
    for (String key : storage.getStorageKeys()) {
      Storage  st  = storage.getStorage(key);
     
      statement.setString(2, TYPE_STORAGE);
      statement.setString(3, key);
      statement.setString(4, st.getUUID()+SPLIT_STORAGE_VERSION_BY+st.getVersion());
      statement.execute();
    }
   
    // save storages
    for (String key : storage.getStorageKeys())
View Full Code Here

       
        // removed? --> no re-creation
        if (!storages.containsKey(uuid))
          continue;
       
        Storage  storage  = storages.get(uuid);
       
        saveStorage(storage, true);
       
        storage.resetHasChanged();   
        successfull.add(uuid);
       
      } catch (Exception e) {
        scs.log(Level.INFO, "Couldn't save "+uuid+", trying again later", false);
        e.printStackTrace();
View Full Code Here

   */
  public static Storage nodeToStorage (Node node) {
    if (!node.hasChildNodes())
      return null;
   
    Storage    storage  = null;
    String    usid  = null;
    int      version  = 0;
   
    for (int i = 0; i < node.getAttributes().getLength(); i++) {
      Node attr  = node.getAttributes().item(i);
     
      try {
        if (nodeAttrStrgVersion.equalsIgnoreCase(attr.getNodeName()))
          version  = Integer.parseInt(attr.getNodeValue());
       
        else if (nodeAttrStrgUSID.equalsIgnoreCase(attr.getNodeName()))
          usid  = attr.getNodeValue();
       
       
      } catch (Exception e) {
        ShowCaseStandalone.slog(Level.WARNING, "Exception while parsing node name="+node.getNodeName()+",value="+node.getNodeValue());
        e.printStackTrace();
      }
     
    }
   
    if (storage == null) {
      // since storage version 6, UUID is used
      if (version >= 6) {
        storage = new Storage(version, UUID.fromString(usid));
       
      } else  {
        // create a new UUID
        storage = new Storage(version, UUID.randomUUID());
      }
     
    }
   
    // debug
    if (Properties.saveDebug)
      ShowCaseStandalone.slog(Level.INFO, "<--- Utilities.nodeToShopStorage: Loading storage --->");
   
    for (int i = 0; i < node.getChildNodes().getLength(); i++) {
      try {
       
        Node   child  = node.getChildNodes().item(i);
        Node   attr  = child.getAttributes().getNamedItem(nodeAttrType);
        String  type  = attr.getNodeValue();
       
        String  name  = child.getNodeName();
        String  value  = child.getTextContent();
       
        // debug
        if (Properties.saveDebug)
          ShowCaseStandalone.slog(Level.INFO, String.format("%-20s=%-45s, type=%s", name, value, type));
       
        if (nodeAttrTypeDouble.equalsIgnoreCase(type))
          storage.setDouble(name, Double.parseDouble(value));
       
        if (nodeAttrTypeInteger.equalsIgnoreCase(type))
          storage.setInteger(name, Integer.parseInt(value));

        if (nodeAttrTypeBoolean.equalsIgnoreCase(type))
          storage.setBoolean(name, Boolean.parseBoolean(value));
       
        if (nodeAttrTypeString.equalsIgnoreCase(type))
          storage.setString(name, value);
       
        if (nodeAttrTypeStorage.equalsIgnoreCase(type))
          storage.setStorage(name, nodeToStorage(child));
       
       
      } catch (Exception e) {
        // don't care
      }
    }
   
    storage.resetHasChanged();
   
    // debug
    if (Properties.saveDebug)
      ShowCaseStandalone.slog(Level.INFO, "<--- Utilities.nodeToShopStorage: Loaded --->");
   
View Full Code Here

TOP

Related Classes of com.kellerkindt.scs.internals.Storage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.