コード例 #1
0
  public String getWorldGroups(Player player) {
    World world = player.getWorld();
    List<String> returnData = new ArrayList<>();

    if (plugin.getXInventories() != null) {
      Main xInventories = plugin.getXInventories();
      String xGroup = xInventories.getConfig().getString("worlds." + world.getName());
      plugin.logDebug("xGroup: " + xGroup);
      if (xGroup != null) {
        returnData.add(xGroup);
      }
    }

    if (plugin.getMultiInvAPI() != null) {
      String worldname = world.getName();
      MultiInvAPI multiInvAPI = plugin.getMultiInvAPI();
      if (multiInvAPI.getGroups() != null) {
        if (multiInvAPI.getGroups().containsKey(worldname)) {
          returnData.add(multiInvAPI.getGroups().get(worldname));
        }
      }
    }
    if (plugin.getWorldInvAPI()) {
      String worldname = world.getName();
      try {
        returnData.add(WorldInventoriesAPI.findGroup(worldname).getName());
      } catch (Exception ex) {
      }
    }
    if (plugin.myWorldsHook != null) {
      if (plugin.myWorldsHook.isEnabled()) {
        returnData.add(plugin.myWorldsHook.getLocationName(player.getLocation()));
      }
    }
    try {
      if (plugin.getMultiverseGroupManager() != null) {
        if (plugin.getMultiverseGroupManager().hasGroup(world.getName())) {
          for (WorldGroupProfile wgp :
              plugin.getMultiverseGroupManager().getGroupsForWorld(world.getName())) {
            returnData.add(wgp.getName());
          }
        }
      }
    } catch (Exception ex) {
      plugin.logError(ex.getMessage());
    }
    if (plugin.pwiHook != null) {
      returnData.add(plugin.pwiHook.getLocationName(world.getName()));
    }
    if (returnData.isEmpty()) {
      returnData.add("");
    }
    return returnData.get(0);
  }
コード例 #2
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());
   }
 }
コード例 #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.");
    }
  }