@Override public boolean updatePlayer(Player player, PlayerProfile profile) { Integer value = profile.get(CUSTOM); if (value == null) { // Specify default value player.setLastDamage(0); return false; } player.setLastDamage(value); return true; }
@Override public void setLastDamage(int damage) { caller.setLastDamage(damage); }
@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()); }