Esempio n. 1
0
 public void save() {
   HashMap<String, RestorationObject> restorationsForDisk = new HashMap<>();
   for (Map.Entry<String, Restoration> entry : RESTORATIONS.entrySet()) {
     String key = entry.getKey();
     Restoration value = entry.getValue();
     RestorationObject tmpRestoration = new RestorationObject();
     for (ItemStack i : value.inventory) {
       if (i instanceof ItemStack) {
         plugin.logDebug("Serializing inventory: " + i.toString());
         tmpRestoration.inventory.add(new ScavengerItem(i));
       }
     }
     for (ItemStack i : value.armour) {
       if (i instanceof ItemStack) {
         plugin.logDebug("Serializing armour: " + i.toString());
         tmpRestoration.armour.add(new ScavengerItem(i));
       }
     }
     if (plugin.isMc19or110()) {
       if (value.offHand instanceof ItemStack) {
         plugin.logDebug("Serializing offhand: " + value.offHand.toString());
         tmpRestoration.offHand = new ScavengerItem(value.offHand);
       }
     }
     tmpRestoration.enabled = value.enabled;
     tmpRestoration.level = value.level;
     tmpRestoration.exp = value.exp;
     tmpRestoration.playerName = value.playerName;
     restorationsForDisk.put(key, tmpRestoration);
     plugin.logInfo("Saving " + tmpRestoration.playerName + "'s inventory to disk.");
   }
   try {
     File file = new File("plugins/Scavenger/inv3.ser");
     FileOutputStream f_out = new FileOutputStream(file);
     try (ObjectOutputStream obj_out = new ObjectOutputStream(f_out)) {
       obj_out.writeObject(restorationsForDisk);
     }
   } catch (IOException e) {
     plugin.logError(e.getMessage());
   }
 }
Esempio n. 2
0
  private void loadLanguage(Scavenger plug) {
    boolean success = false;

    File file = new File(langDir + "/" + languageFileName);
    if (file.exists()) {
      Yaml yaml = new Yaml();
      try {
        plug.logInfo("Loading language file: " + file.getAbsolutePath());
        Reader reader = new FileReader(file);
        @SuppressWarnings("unchecked")
        Map<String, String> map = (Map<String, String>) yaml.load(reader);
        if (map.containsKey(MSG_HEADER)) {
          msgHeader = map.get(MSG_HEADER);
        } else {
          msgHeader = config.getString("Messages." + MSG_HEADER, MSG_HEADER_DEF);
        }
        if (map.containsKey(MSG_INSIDEENEMYFACTION)) {
          msgInsideEnemyFaction = map.get(MSG_INSIDEENEMYFACTION);
        } else {
          msgInsideEnemyFaction =
              config.getString("Messages." + MSG_INSIDEENEMYFACTION, MSG_INSIDEENEMYFACTION_DEF);
        }
        if (map.containsKey(MSG_INSIDEDUNGEONMAZE)) {
          msgInsideDungeonMaze = map.get(MSG_INSIDEDUNGEONMAZE);
        } else {
          msgInsideDungeonMaze =
              config.getString("Messages." + MSG_INSIDEDUNGEONMAZE, MSG_INSIDEDUNGEONMAZE_DEF);
        }
        if (map.containsKey(MSG_INSIDERES)) {
          msgInsideRes = map.get(MSG_INSIDERES);
        } else {
          msgInsideRes = config.getString("Messages." + MSG_INSIDERES, MSG_INSIDERES_DEF);
        }
        if (map.containsKey(MSG_PVPDEATH)) {
          msgPVPDeath = map.get(MSG_PVPDEATH);
        } else {
          msgPVPDeath = config.getString("Messages." + MSG_PVPDEATH, MSG_PVPDEATH_DEF);
        }
        if (map.containsKey(MSG_RECOVERED)) {
          msgRecovered = map.get(MSG_RECOVERED);
        } else {
          msgRecovered = config.getString("Messages." + MSG_RECOVERED, MSG_RECOVERED_DEF);
        }
        if (map.containsKey(MSG_SAVING)) {
          msgSaving = map.get(MSG_SAVING);
        } else {
          msgSaving = config.getString("Messages." + MSG_SAVING, MSG_SAVING_DEF);
        }
        if (map.containsKey(MSG_SAVEFORFEE)) {
          msgSaveForFee = map.get(MSG_SAVEFORFEE);
        } else {
          msgSaveForFee = config.getString("Messages." + MSG_SAVEFORFEE, MSG_SAVEFORFEE_DEF);
        }
        if (map.containsKey(MSG_NOTENOUGHMONEY)) {
          msgNotEnoughMoney = map.get(MSG_NOTENOUGHMONEY);
        } else {
          msgNotEnoughMoney =
              config.getString("Messages." + MSG_NOTENOUGHMONEY, MSG_NOTENOUGHMONEY_DEF);
        }
        if (map.containsKey(MSG_INSIDEPA)) {
          msgInsidePA = map.get(MSG_INSIDEPA);
        } else {
          msgInsidePA = config.getString("Messages." + MSG_INSIDEPA, MSG_INSIDEPA_DEF);
        }
        if (map.containsKey(MSG_INSIDEBA)) {
          msgInsideBA = map.get(MSG_INSIDEBA);
        } else {
          msgInsideBA = config.getString("Messages." + MSG_INSIDEBA, MSG_INSIDEBA_DEF);
        }
        if (map.containsKey(MSG_INSIDEMA)) {
          msgInsideMA = map.get(MSG_INSIDEMA);
        } else {
          msgInsideMA = config.getString("Messages." + MSG_INSIDEMA, MSG_INSIDEMA_DEF);
        }
        if (map.containsKey(MSG_INSIDEUA)) {
          msgInsideUA = map.get(MSG_INSIDEUA);
        } else {
          msgInsideUA = config.getString("Messages." + MSG_INSIDEUA, MSG_INSIDEUA_DEF);
        }
        if (map.containsKey(MSG_INSIDEWGPVP)) {
          msgInsideWGPVP = map.get(MSG_INSIDEWGPVP);
        } else {
          msgInsideWGPVP = config.getString("Messages." + MSG_INSIDEWGPVP, MSG_INSIDEWGPVP_DEF);
        }
        if (map.containsKey(MSG_INSIDEWGPVPONLY)) {
          msgInsideWGPVPOnly = map.get(MSG_INSIDEWGPVPONLY);
        } else {
          msgInsideWGPVPOnly =
              config.getString("Messages." + MSG_INSIDEWGPVPONLY, MSG_INSIDEWGPVPONLY_DEF);
        }
        reader.close();
        success = true;
      } catch (Exception ex) {
        plug.logError("Error reading file: " + ex.getMessage());
        success = false;
      }
    }
    if (!success) {
      // Fall back to our default config.
      msgHeader = config.getString("Messages." + MSG_HEADER, MSG_HEADER_DEF);
      msgInsideEnemyFaction =
          config.getString("Messages." + MSG_INSIDEENEMYFACTION, MSG_INSIDEENEMYFACTION_DEF);
      msgInsideDungeonMaze =
          config.getString("Messages." + MSG_INSIDEDUNGEONMAZE, MSG_INSIDEDUNGEONMAZE_DEF);
      msgInsideRes = config.getString("Messages." + MSG_INSIDERES, MSG_INSIDERES_DEF);
      msgPVPDeath = config.getString("Messages." + MSG_PVPDEATH, MSG_PVPDEATH_DEF);
      msgRecovered = config.getString("Messages." + MSG_RECOVERED, MSG_RECOVERED_DEF);
      msgSaving = config.getString("Messages." + MSG_SAVING, MSG_SAVING_DEF);
      msgSaveForFee = config.getString("Messages." + MSG_SAVEFORFEE, MSG_SAVEFORFEE_DEF);
      msgNotEnoughMoney =
          config.getString("Messages." + MSG_NOTENOUGHMONEY, MSG_NOTENOUGHMONEY_DEF);
      msgInsidePA = config.getString("Messages." + MSG_INSIDEPA, MSG_INSIDEPA_DEF);
      msgInsideBA = config.getString("Messages." + MSG_INSIDEBA, MSG_INSIDEBA_DEF);
      msgInsideMA = config.getString("Messages." + MSG_INSIDEMA, MSG_INSIDEMA_DEF);
      msgInsideUA = config.getString("Messages." + MSG_INSIDEUA, MSG_INSIDEUA_DEF);
      msgInsideWGPVP = config.getString("Messages." + MSG_INSIDEWGPVP, MSG_INSIDEWGPVP_DEF);
      msgInsideWGPVPOnly =
          config.getString("Messages." + MSG_INSIDEWGPVPONLY, MSG_INSIDEWGPVPONLY_DEF);
    }
  }
Esempio n. 3
0
  public void load() {
    Map<String, RestorationObject> restorationsFromDisk;
    File file = new File("plugins/Scavenger/inv3.ser");
    if (!file.exists()) {
      plugin.logDebug("Recovery file '" + file.getAbsolutePath() + "' does not exist.");
      return;
    }
    try {
      FileInputStream f_in = new FileInputStream(file);
      try (ObjectInputStream obj_in = new ObjectInputStream(f_in)) {
        restorationsFromDisk = (Map<String, RestorationObject>) obj_in.readObject();
      }
    } catch (IOException | ClassNotFoundException | ClassCastException e) {
      plugin.logError(e.getMessage());
      return;
    }

    for (Map.Entry<String, RestorationObject> entry : restorationsFromDisk.entrySet()) {
      String key = entry.getKey();
      RestorationObject value = entry.getValue();
      Restoration tmpRestoration = new Restoration();
      tmpRestoration.inventory = new ItemStack[value.inventory.size()];
      tmpRestoration.armour = new ItemStack[value.armour.size()];

      for (int i = 0; i < value.inventory.size(); i++) {
        if (value.inventory.get(i) instanceof ScavengerItem) {
          boolean error = false;
          ItemStack tmpStack = new ItemStack(Material.AIR);
          plugin.logDebug("Deserializing inventory: " + value.inventory.get(i));
          try {
            tmpStack = value.inventory.get(i).getItemStack();
          } catch (Exception e) {
            plugin.logError(e.getMessage() + " => " + value.inventory.get(i));
            error = true;
          } catch (Throwable e) {
            plugin.logError(e.getMessage() + " => " + value.inventory.get(i));
            error = true;
          }
          if (tmpStack == null || error) {
            tmpRestoration.inventory[i] = new ItemStack(Material.AIR);
          } else {
            tmpRestoration.inventory[i] = tmpStack;
          }
          plugin.logDebug("Done: " + tmpRestoration.inventory[i].toString());
        }
      }

      for (int i = 0; i < value.armour.size(); i++) {
        if (value.armour.get(i) instanceof ScavengerItem) {
          ItemStack tmpStack = new ItemStack(Material.AIR);
          plugin.logDebug("Deserializing armour: " + value.armour.get(i));
          try {
            tmpStack = value.armour.get(i).getItemStack();
          } catch (Exception e) {
            plugin.logError(e.getMessage());
          }
          if (tmpStack == null) {
            tmpRestoration.armour[i] = new ItemStack(Material.AIR);
          } else {
            tmpRestoration.armour[i] = tmpStack;
          }
          plugin.logDebug("Done: " + tmpRestoration.armour[i].toString());
        }
      }

      if (plugin.isMc19or110()) {
        if (value.offHand instanceof ScavengerItem) {
          ItemStack tmpStack = new ItemStack(Material.AIR);
          plugin.logDebug("Deserializing offhand: " + value.offHand);
          try {
            tmpStack = value.offHand.getItemStack();
          } catch (Exception e) {
            plugin.logError(e.getMessage());
          }
          if (tmpStack == null) {
            tmpRestoration.offHand = new ItemStack(Material.AIR);
          } else {
            tmpRestoration.offHand = tmpStack;
          }
          plugin.logDebug("Done: " + tmpRestoration.offHand.toString());
        }
      }

      tmpRestoration.enabled = value.enabled;
      tmpRestoration.level = value.level;
      tmpRestoration.exp = value.exp;
      tmpRestoration.playerName = value.playerName;

      RESTORATIONS.put(key, tmpRestoration);
      plugin.logInfo("Loading " + tmpRestoration.playerName + "'s inventory from disk.");
    }
  }