Пример #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);
  }
  @Test
  public void testSharableAPI() {

    Assert.assertTrue(Sharables.all().contains(CUSTOM));
    Assert.assertTrue(Sharables.all().contains(OPTIONAL));

    // Initialize a fake command
    Command mockCommand = mock(Command.class);
    when(mockCommand.getName()).thenReturn("mvinv");

    // Assert debug mode is off
    Assert.assertEquals(0, inventories.getMVIConfig().getGlobalDebug());

    // Send the debug command.
    String[] cmdArgs = new String[] {"debug", "3"};
    inventories.onCommand(mockCommandSender, mockCommand, "", cmdArgs);

    WorldGroupProfile newGroup = inventories.getGroupManager().newEmptyGroup("test");
    newGroup.getShares().mergeShares(Sharables.allOf());
    newGroup.addWorld("world2");
    newGroup.getNegativeShares().add(OPTIONAL);
    inventories.getGroupManager().addGroup(newGroup, true);

    // Verify removal
    Assert.assertTrue(
        !inventories.getGroupManager().getDefaultGroup().getWorlds().contains("world2"));
    cmdArgs = new String[] {"info", "default"};
    inventories.onCommand(mockCommandSender, mockCommand, "", cmdArgs);

    Assert.assertEquals(3, inventories.getMVIConfig().getGlobalDebug());

    Player player = inventories.getServer().getPlayer("dumptruckman");
    // changeWorld(player, "world", "world2");
    // changeWorld(player, "world2", "world");

    // cmdArgs = new String[]{"addshare", "-optional", "default"};
    // inventories.onCommand(mockCommandSender, mockCommand, "", cmdArgs);

    Map<Integer, ItemStack> fillerItems = new HashMap<Integer, ItemStack>();
    fillerItems.put(3, new ItemStack(Material.BOW, 1));
    fillerItems.put(13, new ItemStack(Material.DIRT, 64));
    fillerItems.put(36, new ItemStack(Material.IRON_HELMET, 1));
    addToInventory(player.getInventory(), fillerItems);
    player.setMaximumNoDamageTicks(10);
    int lastDamage = 10;
    player.setLastDamage(lastDamage);
    Assert.assertEquals(10, player.getMaximumNoDamageTicks());
    String originalInventory = player.getInventory().toString();

    changeWorld(player, "world", "world_nether");
    String newInventory = player.getInventory().toString();
    Assert.assertEquals(originalInventory, newInventory);
    Assert.assertEquals(10, player.getMaximumNoDamageTicks());
    Assert.assertEquals(lastDamage, player.getLastDamage());

    changeWorld(player, "world_nether", "world2");
    Assert.assertEquals(0, player.getMaximumNoDamageTicks());
    Assert.assertNotSame(originalInventory, newInventory);
    Assert.assertEquals(lastDamage, player.getLastDamage());
    changeWorld(player, "world2", "world");
    Assert.assertEquals(10, player.getMaximumNoDamageTicks());
    Assert.assertEquals(originalInventory, newInventory);
    Assert.assertEquals(lastDamage, player.getLastDamage());
  }